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.
Advertisement


 
                             
                             
                             
                             
                             
                             
                            