I have started working on a plugin for Sketchup and I was looking for some help. Currently, the plugin lets people select a folder, then open up every single DXF or DWG file in the folder and save it as a separate .skp file. This was made because I need to import .skp files into another 3D program that doesn't take DXF or DWG files.
There is a lot more to the script, but here is the 'workhorse' part of it that imports and saves:
model.import filename, false
outputname = File.basename(filename) + ".skp"
model.save outputname
model.entities.clear!
Now, the listed code is contained in a for loop. This works perfectly, with the exception that each model comes in way too large. I need to prompt the user for a 'scale factor' and use that to scale the model down.
Now, I have done the following before the 'work' part of the code:
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
This prompts the user for a scale factor. And that's all that I know. Am I calling this all correctly. I am more familiar with Objective C and .Net. Is there anything else I need to do to convert the value given into a proper numeric value.
Now, if I have that correct, then perhaps someone might be able to tell me why this doesn't work in my code:
If scaleFactor > 0 then
transform = Geom::Transformation.new([scaleFactor, scaleFactor, scaleFactor])
model.entities.transform_entities(transform, model.entities)
end
Thanks!
If scaleFactor > 0 then
That is not valid ruby syntax. If you keep the Ruby Console open when you run that you will see the following error:
Error: #<SyntaxError: <main>: syntax error, unexpected keyword_then, expecting end-of-input
Instead, use if scaleFactor > 0
Also, you are feeding the UI.inputbox
an Integer
- which means that SketchUp will cast the return value back to an Integer
. You probably want to specify float values in defaults = [0.0]