entityID doesn't update in a group copy


When I group some elements for instance a Face and 4 edges, I have some entityID for the elements inside.
My problem is when I copy this group , the entities inside the new group have the same entityID.

I have found a solution with the GUI if I enter the group, then entityID are changed/updated.
But I’m looking for a pure Ruby solution as I want to make my script fully work by its self.

The persistent_id and the inspect are updated too.
Check this example :

ss = Sketchup.active_model.selection
#select group 1
puts ss[0].entities[0].entityID, ss[0].entities[0].persistent_id , ss[0].entities[0]


#make a copy of group 1 and select it
puts ss[0].entities[0].entityID, ss[0].entities[0].persistent_id , ss[0].entities[0]


I use Sketchup make 2017

Is it a bug or is it the way it suppose to work?
Do you a solution for me ?

Thanks !

Just a quick tip before I go to bed:
Try to use:
The Group #make_unique method…

“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.”
. :sleeping:


… and for IDs that persist across sessions, favor the Entity#persistent_id method.


I thought this method was only for Component !
Amazing ! Thank you.

1 Like

Yea! The groups are a kind of special component in SU.
Among other similar/same methods, it is the most “revealing”:
The Group #definition method is used to retrieve the component definition for this group.
(Returns : (Sketchup::ComponentDefinition) ) :wink:

( Edit
After making it unique, beside the above mentioned id’s even its definition get its own unique definition name: Group#1 , Group#2…etc)


how to #make_unique all group in model??? that group create in sketchup. not ruby.

SketchUp for Schools (web) doesn’t have ability to use Ruby.
To make the groups unique you need to go into to its editing context and then
you can close it without really editing.

If you are using desktop version of Sketchup then there are several different ways to do it by Ruby.

group_definitions = Sketchup.active_model.definitions.find_all{|e| e.group?}
groups = []; group_definitions.each {|e| groups.concat(e.instances) }
count = groups.size

this find all group. but when i copy group in model. count is wrong because we neeed make_unique groups. how to do it with ruby???

Please update your profile, if you are using ruby means you are working with SketchUp Pro. Also write your code using the right sintax ([How to] Post correctly formatted and colorized code on the forum?)

Regarding your post, what do you really need? The amount of group instances or the amount of group definitions?

This code shows you the amount of active visible groups and their names

mod = Sketchup.active_model
ents = mod.active_entities
defsGroup = []

gr = ents.grep(Sketchup::Group)
gr.each {|e| defsGroup.push(e.definition.name) if e.respond_to?(:definition) && !e.hidden?}

puts "Entities amount:" + ents.count.to_s
puts "Visible Groups amount:" + gr.count.to_s
puts "Visible Unique groups amount:" + defsGroup.uniq.count.to_s
puts "Group names:"
puts defsGroup
puts "Unique group names:"
puts defsGroup.uniq
def make_all_groups_unique( model = Sketchup.active_model )
  g_defs = model.definitions.find_all(&:group?)
  model.start_operation("Make all groups unique", true)


thank you…but this is not make_unique for all sub group. :pleading_face:

It makes unique every instances of group definitions of the model, regardless if it is nested or not.

not…it just make unique parent group not sub group.

Is it possible that it is a component and not a group?

def run_this()
  model = Sketchup.active_model
  g_defs = model.definitions.find_all(&:group?)
  1. open sketchup / new sketchup
  2. create one group
  3. run_this >>> g_defs.size = 1 Correct
  4. copy group by tool
  5. run_this >>> g_defs.size = 1 Uncorrect, should be 2

Copying a group does not make it unique.
Both group instances will share the one definition.

exactly group

my question…how to make it unique??

“brute force” method:

def g_def_size(model)

def instance?(obj)
  obj.is_a?(Sketchup::Group) || obj.is_a?(Sketchup::ComponentInstance)

def recur_group_make_unique(ents)
    next unless instance?(e)
    e.make_unique if e.is_a?(Sketchup::Group)

def all_groups_unique
  model = Sketchup.active_model
  puts "gdef size before: #{g_def_size(model)}"
  model.start_operation("Make all groups unique", true)
  puts "gdef size after: #{g_def_size(model)}"
1 Like