I’m trying to create a plugin that does a context click on a group and sends it to a new instance of sketchup for editing (some editing done by code). i use the UI.savepanel to get the path and create the skp file and open it with the UI.openURL() or Sketchup.open_file(). how do i get a handle on the new model instance to continue with the code functionality.
Note:
the Sketchup.open_file() asks to save and closes my original model before i get to the new model instance
where the UI.openURL() does not ask to save nor closes the original model before opening the new instance.
it seems i can get a @second_model = Sketchup.active_model handle with the Sketchup.open_file() method.
Probably because it has to close the original model first.
but how to copy a group over to the new instance? any Suggestions?
Save the definition as a SKP file (Class: Sketchup::ComponentDefinition — SketchUp Ruby API Documentation) - then you can launch a new instance of SU (if you are on Windows) to open the SKP file. To launch a new instance of SU you need to find the install location of SU. If you are on Mac you cannot open a new instance, but you can open a new model window.
Btw, why do you need to start a new instance of SU for editing made by code? Why not edit the group in-place?
On my PC if I use: UI.openURL("file:///#{full_path_to_some.skp}")
It opens it in a new instance of SketchUp and leaves the existing model open.
Assuming that is what you want…
In the original model have your ruby code start an operation, make a component of the group and do a save as on it as “full_path_to_some.skp”, then abort the operation, the group is back as it was, now open the “full_path_to_some.skp” as outlined above and you are editing the group’s contents in the separate SKP.
I don’t see why your code can’t simply edit using the group’s entities context “in place”, separating what it does from the rest of the model…
If you want to keep a ‘backup’ of the starting group then make a copy [in code] and use make_unique on it ensure it’s not overwritten…
to get the ruby to continue into the spawned model, you need to stay in the same SU instance…
this is part of one of mine…
# assume grp and new_skp are defined elsewhere...
ins = grp.to_component
defn = ins.definition
# named only to check if it's been undone...
defn.name = "Explode Me Later"
defn.save_as(new_skp)
# revert original to last save...
count = 0
20.times do
if Sketchup.active_model.modified? == false && Sketchup.active_model.tools.active_tool_name != 'CameraZoomTool'
p count if count > 3
break
else
count += 1
Sketchup.undo
end
end
Sketchup.open_file(new_skp)
# add code here that runs in the new model...
It’s not so much for editing the group. it’s for setting it up in a new model environment to prepare it for sending to layout for dimensions.
I design custom steel parts that all fit together like a puzzle. once the entire puzzle is made then i currently take each piece and save it in a .skp template with some scenes and styles
each puzzle piece can have multiple smaller pieces that i need to spread out to prepare it for layout drawings.
so this is why i place it on it’s own in a model. i’m just trying to do it faster and more efficiently with code.
I’m currently saving the group into a new .skp file, but i want the code to create the standard scenes and do a few operations in the new model. i don’t think it’s possible to do transformations on a .skp file that is not opened.
so this is why i’m trying to start an operation in the original model that continues the code over into the new model. such as creating the standard scenes and applying a few transformations.
I will try john_drivenupthewall’s method of continuing the ruby in the newly opened model. i hope i have explained well enough what i’m trying to accomplish. and thank you for your responses
BTW thomthom it was good to meet you at BASECAMP in Steamboat Springs back in June