Delete the same layer element (objects)

Delete the same layer element

mod = Sketchup.active_model # Open model
ent = mod.entities # All entities in model
sel = mod.selection # Current selection
sel.grep(Sketchup::Group) do | grp |
if grp.layer == @zc_layer 
ent.erase_entities grp

only delete one grp

mod = Sketchup.active_model 
ent = mod.entities 
sel = mod.selection 
grps_to_erase = sel.grep(Sketchup::Group).select do | grp |
  grp.layer == @zc_layer 
ent.erase_entities grps_to_erase 
1 Like

Thanks, great run

1 Like

Never erase while iterating a collection because the iteration will stumble as the number of items changes. This is the proverbial “Pulling the carpet out from beneath you.”

1 Like