Is copy a reference?

I copied a group like this:

group2 = group1.copy

When group1 was deleted, group2.deleted? was also true. How can completely copy a group, instead of a reference?

I keep moving your threads to the Developer section, perhaps you could place them there yourself in future.

1 Like

Thank you. Yes, I will do.

Even better to move more down to [Ruby API].

1 Like

To be honest all the coding stuff is beyond my understanding, so I only ever move things like this into the parent category so at least the right people are seeing it.

1 Like

I guess it is because the copy of the group will share the common definition until using Group#make_unique-instance_method

No. A quick test shows that they each have their own separate definition …

group = Sketchup.active_model.entities.add_group
group.entities.add_line([0,0,0],[100,100,100])
group2 = group.copy
#<Sketchup::Group:0x000001cbb7ea5ae0>

group.definition == group2.definition
#=> false

group.definition
#<Sketchup::ComponentDefinition:0x000001cbb7e7a9f8>

group2.definition
#<Sketchup::ComponentDefinition:0x000001cbb7ea5c70>
group2.deleted?
#=> false
group.deleted?
#=> false

group.erase!

group.deleted?
#=> true
group2.deleted?
#=> false
1 Like