I need to clear Sketchup.active_model for loading new entities? Use the code below to do it?
Sketchup.active_model.entities.clear!
How about the component definitions? Need to delete all definitions too?
I need to clear Sketchup.active_model for loading new entities? Use the code below to do it?
Sketchup.active_model.entities.clear!
How about the component definitions? Need to delete all definitions too?
There is no single method for emptying a model.
You can remove different types of objects separately.
# Root entities
Sketchup.active_model.entities.clear!
# Component definitions
definitions = Sketchup.active_model.definitions
definitions.to_a.each { |d| definitions.remove(d) }
# Materials
materials = Sketchup.active_model.materials
materials .to_a.each { |m| materials .remove(m) }
You could also try loading a model that you have previously emptied using Sketchup.open_file
.
TestUp has a helper method for use in tests that clears/resets the model: