Delete all layers via ruby
-
does anyone know if this is possible: delete ALL existing model layers and put all geometry on layer 0?
i looked around in the forum and in the api, but only found a way to remove a layer by name or index (only for 2015).
i'm trying to integrate it in a batch process
-
Probably the easiest way would be to iterate through all the geometry in the model and assign layer0 to everything, then invoke Sketchup.active_model.layers.purge_unused.
-
yes, i did that, it worked until i got stuck trying to dig through groups and components...
-
m=Sketchup.active_model; m.start_operation('!'); m.entities.each{|e|e.layer=nil}; m.definitions.each{|d|d.entities.each{|e|e.layer=nil}}; m.layers.purge_unused; m.commit_operationReassigns everything [including things inside defiintions etc] to use 'Layer0', then purges all unused layers [i.e. all layers except 'Layer0']. It is one step undo-able.
-
Thanks TIG, you are the best!

so you are mining for entities (including groups i presume), AND component definitions...
-
Yes everything.
All entities in all entities-collections.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better π
Register LoginAdvertisement