我正在用 Ruby 创建一个插件。此时,我无法在 .txt 文件中插入添加到 Sketchup 模型的坐标。
这是我的代码:
require 'sketchup.rb'
SKETCHUP_CONSOLE.show rescue Sketchup.send_action("showRubyPanel:")
$stdout = File.new('file.txt', 'w')
module HWmakemyownplug
def self.fileplug
model = Sketchup.active_model
#Make some coordinates.
coordinates = [[2,0,39],[0,0,1],[1,1,0]]
#Add the points in Sketchup. This works!
coordinates.each { |point| model.active_entities.add_cpoint(point) }
#Puts the coordinates to the textfile 'file.txt'. This doesn't work!
$stdout.puts(coordinates)
end #def self.fileplug
end #module makemyownplug
if (!file_loaded?(__FILE__))
#Add to the SketchUp tools menu
extensions_menu = UI.menu("Plugins")
extensions_menu.add_item("testtesttest") { HWmakemyownplug::fileplug }
# Let Ruby know we have loaded this file
file_loaded(__FILE__)
end
当我单击菜单 > 插件 > testtesttest 时,必须打印坐标。
你忘记在$stdout.puts(coordinates)之后关闭文件
$stdout.close
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句