3D Export capabilities with Ruby
-
Would it be possible to create a ruby which would export only the SELECTED geometry in a model to a KMZ file (or perhaps a selection of groups or components with each group or component placed their own separate KMZ using their component name or group name for the name of the KMZ)?
It would be helpful for organizing content in Google Earth..
-
Hi John, I thought it would be possible, but I am not having any luck actually getting it to work like I thought it should. So I have a questions for the Ruby folks:
I thought that model = Sketchup.active_model sets "model" to be a reflection (for lack of the right word) of the current model. And I thought that if I was inside a group, that model was essentially everything within that group, but nothing above it in the heirarchy (so none of the parent entities). So I thought I could go into the component I wanted to export and then start the code with
model = Sketchup.active_model model.export "mymodel.kmz", true
And that in my mind was going to export everything within the component I was editing, but nothing outside it. But that doesn't work. So I'm guessing that Sketchup.active_model is not exactly what I think it is. Is that right? Is Sketchup.active_model always the entire model? Or is it something different altogether?
Chris
-
Sketchup.active_model
is always the whole model.
Sketchup.active_model.active_entities
is the entities in the currently open group/component.But I suspect that you won't have the export method available from active_entities.
-
Oh, now I remember what I was thinking of. Sketchup.active_model.active_entities is all the entities inside the current group/component. It's the active_entities that narrows it down to current group/component only. Bummer.
So is there a way to tell SKetchup.active_model to be anything less than the entire model?
Chris
-
Perhaps this procedure could be scripted:
1- User selects Group(S) and or Component(S) to export. Names of this entities are "remembered"/stored.
2- Reverse the selection (I found this code in an old script)
class Invert def Invert.toggle_all mod = Sketchup.active_model ss = mod.selection objects = mod.active_entities # Everthing in the current edit level. if (ss.empty?) then UI.beep return end objects.each {|o| ss.toggle(o) # Flip current selection set. } end # Invert.toggle_all end # Class
3- Those entities in this inverted selection set are "remembered"/stored (I assume locked entities are automatically ignored)
4- Names of all entities in inverted selection set are hidden.
5- Then execute File > Export > 3D. The names collected at Step 1 are used as the model name (multiple names are separated my a comma or something similar >>> User given opportunity to override and type in a different name for the KMZ).
6- Export completed.
7- Using the names of the inverted selection set, an UnHide Last is executed.
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
If it is possible to hack into the KML which is contained in the KMZ at this point, then rename the "model" folder contained within it to that of the KMZ file. See below.
Note, if a Colladae file could be made to store latitude, longitude, and elevation info, then that might be an even cleaner solution.
-
JC I think your hidden ("not selected") things would still export.
Perhaps it's more possible if you invert the selection.
Unlock anything that's locked in that new selection.
Erase all new selection.
Exported the model (what's left is the original selection).
THEN undo everything so nothing is selected, unlocked or deleted.The exported file won't be undone [I hope] ?
-
@tig said:
The exported file won't be undone [I hope] ?
Exporting model doesn't seem to appear in the undo stack.
-
Tig,
So far, from my testing, hidden objects are not being exported. Try it yourself. If you create KMZ file, change it to a ZIP extension and open it. Examine the diretory and file sturcture.If you want to examine the embedded KML file (or KMZ file directly), try Northgate's free KML editor.
Advertisement