Should I put entities in group.entities, or group.definition.entities?

There are group.entities and group.definition for a group. I am confused. When I put faces or edges into a group, where are they expected to go?

They should go into a .entities context.
will both work.
They point at the same context…


If the user create a group and make a copy without editing its contant, both group instance will share the same definition.

Edited: (Considering explanation of @DanRathbun below)
So if you choose one of the group instance and add e.g. a cpoint to its definition entities it will be added to both instances. However if you add to group entities instead it will be only on that instance.

  • - So if you choose one of the group instance and add e.g. a cpoint to its group.definition.entities it will be added to this shared definition, therefore it will be in both instances. However if you are using group.entities instead it will be silently make the group to have a unique definition and the cpoint will be added to this new definition entities.

See also:
The #make_unique method is used to force a group to have a unique definition. If the group is already unique in the model, nothing happens.
Copying a group in SketchUp will create a group that shares the same definition. SketchUp implicitly makes group unique when edited from the GUI, and from a user point of view groups could be thought of as always being unique.

try this:

groups = Sketchup.active_model.selection.grep(Sketchup::Group)
puts "g0: #{groups[0]}"
puts "g1: #{groups[1]}"
groups[0].definition.entities.add_cpoint [0,0,10]
puts "g0: #{groups[0]}"
puts "g1: #{groups[1]}"

then this:

groups = Sketchup.active_model.selection.grep(Sketchup::Group)
groups[0].entities.add_cpoint [0,0,20]
puts "g0: #{groups[0]}"
puts "g1: #{groups[1]}"



Thanks, I got it.

This not true and never has been.
Group.entities always was a wrapper method for Group.definition.entities.
(Ie, a group is an instance and does not have an Entities collection.)

The API used to try to hide the fact that groups were special component instances.
It did not make sense, so the Group.definition was exposed in v2015.


You are right. I edited my post above, hoping that I’m using the right wording now… :blush:

1 Like

Thanks, got it. They are the same thing.

1 Like