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
end
end
mod = Sketchup.active_model
ent = mod.entities
sel = mod.selection
grps_to_erase = sel.grep(Sketchup::Group).select do | grp |
grp.layer == @zc_layer
end
ent.erase_entities grps_to_erase
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.”