YES I see the same issue using your convoluted code.
One problem is that you keep creating new groups, then explode them almost immediately. SketchUp will purge a group definition if it has no instances.
Examine this snippet …
num_copies = 4
@model.start_operation('Create Spiral', true)
ents = @model.entities # All entities in model <--- DON'T USE !
sel = @model.selection
rot_origin = Geom::Point3d.new(0,0,0)
rot_axis_vector = Geom::Vector3d.new(0,0,1)
shift = Geom::Vector3d.new(0,0,10)
# Define rotation by axis and angle
tr_rot = Geom::Transformation.rotation(rot_origin, rot_axis_vector, 10.degrees)
# Define translation
tr_mov = Geom::Transformation.translation(shift)
actent = @model.active_entities
grporg = actent.add_group(sel.to_a)
grpdef = grporg.definition
transform = tr_rot * tr_mov
t = grporg.transformation
for i in 1..num_copies
t *= transform
EDITED the above example to initially set the reference
t to the initial groups’s transformation.
(Was previously just starting from an identity transform.)
1. Always use
@model.active_entities when using a user’s selection set.
2. Notice how first each new transformed group instance is added, and only afterward do we explode the groups one by one, in reverse order, allowing SketchUp to uniquify the exploded objects. It does this automatically because the originals are still within the group’s definition’s entities collection. Only when the last (which is the first and original) group instance is exploded does SketchUp keep the PIDs of the selected items and then purges the unused group definition because no more instances exist.
3. So checking the model after using the above there are no more issues with PIDs.
4. Learn to use the
* method of
Geom::Tranformation class to combine transforms.