Sketchup API和缩放模型

时间:2013-10-14 17:17:22

标签: ruby sketchup

我已经开始为Sketchup创建一个插件,我正在寻找一些帮助。目前,该插件允许人们选择文件夹,然后打开文件夹中的每个DXF或DWG文件,并将其另存为单独的.skp文件。这是因为我需要将.skp文件导入另一个不接受DXF或DWG文件的3D程序。

脚本还有很多内容,但这里有导入和保存的“主力”部分:

 model.import filename, false
 outputname = File.basename(filename) + ".skp"
 model.save outputname
 model.entities.clear!

现在,列出的代码包含在for循环中。这种方法非常有效,除了每个模型都太大了。我需要提示用户输入“比例因子”并使用它来缩小模型。

现在,我在代码的'work'部分之前完成了以下操作:

 scalePromptResult = UI.messagebox "Woudl you like to adjust the scale for ALL models being converted?", MB_YESNO

 scaleFactor = 0

 if scalePromptResult == 6
      prompts = ["Please enter the scale factor you want to use"]
      defaults = [0]
      inputArray = UI.inputbox prompts, defaults, "Scale Factor"
      scaleFactor = inputArray[0]
 end

这会提示用户输入比例因子。这就是我所知道的。我是否正确地称呼这一切。我更熟悉Objective C和.Net。还有什么我需要做的就是将给定的值转换为正确的数值。

现在,如果我有正确的话,那么也许有人可能会告诉我为什么这在我的代码中不起作用:

 If scaleFactor > 0 then
      transform = Geom::Transformation.new([scaleFactor, scaleFactor, scaleFactor])
      model.entities.transform_entities(transform, model.entities)
 end

谢谢!

1 个答案:

答案 0 :(得分:0)

  

If scaleFactor > 0 then

这不是有效的ruby语法。如果在运行时保持Ruby控制台处于打开状态,您将看到以下错误:

Error: #<SyntaxError: <main>: syntax error, unexpected keyword_then, expecting end-of-input

相反,请使用if scaleFactor > 0

此外,您正在提供UI.inputboxInteger - 这意味着SketchUp会将返回值转换回Integer。您可能希望在defaults = [0.0]

中指定浮点值