Set Group instance name without making it unique

I can manually edit or set copied group instance names without them becoming unique, but using name=(name) makes the group unique. Is there a way to set the group instance name using ruby without making it unique?

The answer is in the API documentation:

Sketchup::Group

Groups in SketchUp are very similar to components, but can from a user point of view be thought of as unique objects. Groups can be instanced when copied but are silently made unique when edited through the GUI. To honor this behavior, make sure to call [#make_unique]

Furthermore

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. To honor this behavior, call this method before editing a group through the API.

Then, to provide an answer to specific question:

The #name= method is used to set the name for the group.

Thanks Dezmo. I am trying to process groups similar to how Deep Unique processes components. 4 groups share a definition and I want to make 2 of them unique (to a new shared definition, same as initial SketchUp state just severed from the other 2). More plainly - I want sever the selection from the rest of the model cleanly while maintaining the same nesting and definition hierarchy. The only problem I am having is re assigning group instance names that are lost in the process. I was hoping the Ruby API could match SketchUps UI instance naming result (apply the name without making the group unique), but I guess it can’t in this case.

The way I see it, the instance #name= method should act only upon the group instance and be distinct from the definition’s name= method.

Meaning that I would expect groups at the top level to not be made unique simply by changing their instance name property.

But this goes “out the window” when dealing with nested groups. Changing a property for a nested group instance changes it in all parent entities because they share the same instance.

Well you could make the 3rd unique, then replace the 4th with an instance of the 3rd’s definition. Your code would need to copy all properties and attribute dictionaries (if any.)

Hey Dan. :waving_hand:

Yes this is what I have done. But naming the copy forks it to a new definition. An example script:

model = Sketchup.active_model
ents  = model.active_entities
model.start_operation('name probe', true)
g1 = ents.add_group
g1.entities.add_face([0,0,0], [10,0,0], [10,10,0], [0,10,0])
g2 = ents.add_instance(g1.definition, Geom::Transformation.new([20,0,0]))
p g2.class                         # Sketchup::Group
p g1.definition == g2.definition   # true, shared
g2.name = 'Leg'
p g1.definition == g2.definition   # false, renaming forked it
model.abort_operation

OK, I see what you see. I tested back to SU2024 and also 2017.

I believe this should be a bug, as there is no API contract that the name= instance method should internally call #make_unique. It is also unexpected as well as (in most cases) undesirable.

OK thanks Dan, I’ve filed it on the API issue tracker:

https://github.com/SketchUp/api-issue-tracker/issues/1125