Okay, I duplicated your results (I realize that the statements associated with my steps are not quite correct). What happened to me is that I assigned variable A to group A at step 3, and then I completed the remaining steps. When I typed
p A.name into the Ruby console, I see "A2" and not "A".
It indicates that first occurrence of A in the entities chaining was turned into a new instance, and the A group inside of B2 retained it group identifier.
I duplicated my steps a second time with more intermediate output, restarting Sketchup with a new model from scratch:
a) Delete the startup Sketchup person component;
b) Draw a rectangle into a cube, triple click it, group it, and name it “A”.
At the console enter:
entities = Sketchup.active_model.entities
entities[0] ==> #<Sketchup::Group:0x0000000b95c670>
(I will be comparing object ID's instead of GUIDs. Each instance of
the Sketchup application cranks out its own ID numbers,
results will differ each time.)
c) I drew a 2d square, selected everything, grouped them and named it “B”. The ordering of my selection was such that the grouped object is “entities[5]”. Results may vary.
At the console:
A = entities[0].entities[5] ==> #<Sketchup::Group:0x0000000b95c670>
B = entities[0] ==> #<Sketchup::Group:0x0000000b965748>
So far so good, the first group hasn't changed it's ID number.
d) I copied and pasted object “B”.
At the console:
B2 = entities[1] ==> #<Sketchup::Group:0x0000000b9c6408>
p B2.name ==> "B"
I expect its Group ID number to be unique from the other one because it has a different transformation (i.e. position is different).
e) I renamed the copied entity from B to B2.
At the console:
p B2.name ==> "B2"
A2 = B2.entities[5] ==> #<Sketchup::Group:0x0000000b95c670>
p A2.name ==> "A"
It can be seen that it is the exact same group ID as we originally started with. It even has the same name and transformation. For something like a hundred leaves on a hundred trees, it not only saves memory in the file, but in the graphics card memory as well. But it sure makes everything else confusing.
f) Double click B2 to enter edit mode on it, select the A group object and rename it to A2.
Giving it a unique name will result in Sketchup having to make it a separate instance.
At the console:
p A, A.name ==> [#<Sketchup::Group:0x0000000b95c670>, "A2"]
p A2, A2.name ==> [#<Sketchup::Group:0x0000000b95c670>, "A2"]
Whoops, I seemed to have changed the name of group “…b95c670”, which is referenced by both A and A2. Steps “a” to “e” are standard Sketchup, I haven’t explored this deep before to know if this step “f” is.
I now know that I need to update the object that “A” references:
A = entities[0].entities[5] ==> #<Sketchup::Group:0x0000000ba86730>
p A.name, A==A2 ==> ["A", false]
At first I said it was expected behaviour, but now I can’t say I ever tracked the operations in such detail to know. I can’t call it a bug, but a feature that saves memory, but there is a gotcha when modifying a duplicate enitity and the internal modifications create an instance in another entity.
I do know that the copy behaviour exists with components as well if it is nested inside of another grouped object. Similar results should occur with GUIDs.