I can use below commands to save definiton to skp file successfully.But it failed when use again and again.Who know if this is issue or how to avoid this issue?
definition = selection.first.definition
status = definition.save_as(“C:/Users/CTDS002/Desktop/Debug/temp/temp1.skp”)
What does selection.first
return ?
What does definition
return ?
It needs to be a component_instance.definition
with the correct type of argument…
How do you mean it fails? Is it raising a Ruby exception? It it silently failing to write to the file?
Also, does the subfolder exists ?
C:/Users/CTDS002/Desktop/Debug/temp
It must be there so the file can be written to it ??
Ruby return true instead of raising a exception and it is silently failing to write to the file.
First time,the definition what be selected can be save to temp1.skp,but second ,third and … it does not write the definition to temp1.skp.I also try change the floder and filename, it have not any effect.However I reopen the sketchup and it can save to temp1.skp success at first time.
I think ruby has execute the command “status = definition.save_as(“C:/Users/CTDS002/Desktop/Debug/temp/temp1.skp”)”,but it does not generate temp1.skp.
All code as below:
model = Sketchup.active_model
selection = model.selection
number = selection.length
if number==0
UI.messagebox “请选择组件”
else
definition = selection.first.definition
status = definition.save_as(“C:/Users/CTDS002/Desktop/Debug/temp/temp1.skp”)
puts definition
puts status
end
Yes, the subfoldeer exist and it can save success at first time action.Then it will save fail after first time action.
Please quote code correctly in forum …
Reference Open API Issue:
Do you have any anti-virus software or backup software that might read (and lock) the file?