Different between entities and definition.entities

Dear friends,
Sorry to ask you this simple task but I cannot find answer in internet.
What is different between “group.entities” and "group.definition.entities?
Thank you in advance,

Nothing.
A model or a definition will have .entities [a model can also use .active_entities useful in case the user is inside and edit.
A definition has .entities and a definition covers components [as listed in the components-browser], and also includes groups [which are not listed there] - and also the special type images.
Placed component-instances do not have entities, but the instance.definition.entities gets it.
group.entities is simply a shortcut to group.definition.entities
To see this select a group, use group=Sketchup.active_model.selection[0] in the Ruby Console.
Then puts group.entities.to_a
Then puts group.definition.entities.to_a
The output should be the same !

1 Like

Just some notes on top of TIG explanation:
Check here the description of
Group#make_unique-instance_method .
…and try this:

Create two edges!
Make a group of it!
Copy the group with the move tool!
Select both groups!
Run this

group0=Sketchup.active_model.selection[0]
group1=Sketchup.active_model.selection[1]
p group0.entities.to_a
p group0.definition.entities.to_a
p group1.entities.to_a
p group1.definition.entities.to_a
p

You will see four same array.

Now double click one of the group to edit, then close (go out from editing) without changes.
Select both groups!
Run the code above again.
You will see some changes…

1 Like

Simply put, group.entities is a wrapper method that calls self.definition.entities.


Backstory: In the past the powers that be wished to hide the fact that groups are really just component instances with “special” behaviors. So they did not give direct API access to the group’s definition via a #definition getter method.

They instead expected coders to only need to access the group definition’s entities collection so they exposed that via group#entities from the beginning of the API.

But API coders still needed to get to the group’s definition object and had to use workaround search methods that were susceptible to an API bug, so they finally added the group#definition getter method in SketchUp 2015.

2 Likes

As you know your codes are so interesting for me. Unfortunately your codes dose not work for me. Also I run following codes. Not important how many groups are in model answer always is “0”.

sel = Sketchup.active_model.selection
p sel.size

You must manually select the groups. You know, click on it or use window selection…

image
(Or use the .add method )

1 Like

Different is “[#Sketchup::Edge:0x000001e418156b68, #Sketchup::Edge:0x000001e418156b40]”. Does it effect on our codes?

I don’t think… (…if you understood or even executed properly the steps above)

1 Like