As title, I plan to go through a list of definition, get the components of each definition and save them to separate files.
But I couldn’t find a way to open a new model, copy the entities and save that model.
My current solution is to select the instances of definitions, then invert the selection to delete other, save to new file and undo. But that will not work with large data, and contain too much unpurged data.
def_list = model.definitions["tree-1"]
Sketchup.active_model.start_operation("Export to new file", true)
selection.add def_list.instances
selection.invert
selection.to_a.each { |entity|
entity.erase!
}
def export_instances(definition)
model = Sketchup.active_model
entities = model.active_entities
instances = definition.instances
#note : All instnaces below must have a common parent
group = entities.add_group(instances)
def_to_export = group.definition
success = def_to_export.save_as( "c:/export.skp" )
#clean up:
group.explode
end
export_instances( Sketchup.active_model.definitions["tree-1"] )