Delete specific Group



I have a collection of boxes that belong to a layer called “Boxes”. This is the way I create every box:

        entities = model.active_entites
        model.active_layer = 'Boxes'
        gr = entities.add_group = "box_" + box_name
        entities = gr.entities
        # Here I define the faces of the box 

box_name is requested by a UI.inputbox. The boxes are correctly generated.

The question is, how to delete a specific group? I provide a name to the box, but I just don’t know how to have access to a group and remove it. Sorry, I’m new to the Ruby API.


Let’s assume you have a box named ‘box_123’.
Set a reference to that string, e.g.


To find it [or all if there is more than one with that same name] use something like:

gps = model.active_entities.grep(Sketchup::Group).find_all{|g| }

Now gps is an array containing nil [if no match], or one or more groups having that name.
Just to see if it works add this:


To erase the group[s]

model.active_entities.erase_entities(gps) if gps[0]

Or to erase just one thing at a time - let’s say that it’s referenced as ‘group’:



That is exactly what I was looking for. It works perfectly, thanks!