Save panel when new SU file
-
Hey,
In a script I try to make a new SU file to save in the components folder and draw a text object into. Therefore I first have to know the path of the old SU file in order to be able to open it again after opening, drawing in, saving and closing the new SU component file.
I do this with an inputpanel so I can save the path the user has chosen, but when I then make a new SU file withSketchup.file_new
Sketchup automatically asks the user to save the current file and opens a second save panel again.
def make_skp() ss = Sketchup.active_model.selection skp = Sketchup.active_model.name # Name of the current SU model path1 = Sketchup.active_model.path # Path of the current SU model # Settings of the selected text object tekstlabel = ss[0] v = ss[0].vector name = ss[0].text l = ss[0].leader_type a = ss[0].arrow_type p = ss[0].point tekstlabel.erase! # Delete the text object UI.messagebox "Please save your SU file." path2 = UI.savepanel("Save as",path1,skp) # Check if path2 ends with skp p = path2.split(".") if p[1] != "skp" path2=path2+".skp" end Sketchup.active_model.close_active # Close the current SU model su = Sketchup.file_new # Make a new SU file for the text object path3= File.join($components, "Opbouw", name+".skp") su.active_model.save(path3) # Make a new text object with the same settings in the new file t = su.active_model.entities.add_text(name,[0,0,0]) t.vector = v t.leader_type = l t.arrow_type = a t.display_leader = true su.active_model.save(path3) # Save the new SU file su.active_model.close_active # Close the new SU file # Open the old SU file again Sketchup.open_file(path2) end
The code I wrote works perfectly, but does anyone has an idea of how to avoid this second savepanel witch is a little bit annoying to fill in all over again?
-
Why not use the save_as method of the component definition?
http://code.google.com/apis/sketchup/docs/ourdoc/componentdefinition.html#save_as
Going about creating a new model for a component sounds cumbersome.
-
Thanks, can't see why i didn't think of that...
Advertisement