What is the difference between two equal not unique components?

What is the difference between two equal not unique components? When both are in the root model level then “==” returns false. But if they are nested, I can not get the difference with which I could detect they are not the same instance.

Please explain yourself more clearly.
Two instances can never be ==, but their definition could be ==.

At the moment you seem to be jumbling up component instances and definitions…

instance1==instance2 is always false, as they are different entities
But instance1.definition==instance2.definition can be EITHER true OR false - if they are or are not both instances of the same definition

Is this what concerns you ?

1 Like

mod = Sketchup.active_model
sel = mod.selection
aa = sel[0] # in model root level
bb = sel[1] # in model root level
aa is copy of bb
e.definition.entities.each{|f| @aa = f}
e.definition.entities.each{|f| @bb = f}
p aa == bb # returns false
p @aa == @bb # returns true

Sorry! I do not speak English well but I understand it :slight_smile:

aa and bb appears to be ComponentInstance objects while @aa and @bb are the last Entity (DrawingElement to be precise) in the Entities collection belonging to their shared ComponentDefinition. As the ComponentDefinition is the same for both instances, its last child element is also the same.

1 Like

So, there is no way to detect that @aa and @bb are not the same instance unless I determine if they have same parent instances in root level?

@aa and @bb are the very same object. How could something not be the same as itself?

Because @aa and @bb are in different parent components. @aa and @bb are instances each for themselves. I just want to detect it. I have array of components and I do not want to have duplicate components in the same array. Because @aa and @bb are components each for themselves, i want them both in the array. So if i have an array that contains @aa, array.include? (@bb) will return me “true” and i will not get them both in that array.

You are muddling up terminology.
The ‘components’ that you see in the model are called component instances.
These are instances of component definitions - you view those in the Components Browser > Model tab.

It is possible to have several instances of the same definition.
So instance1==instance2 is always false as the two instances are separate things.
However, instance1.definition==instance2.definition could be true or false !
If the two instances are created from the same definition it’s true, otherwise it’s false !

You then confuse yourself further by comparing the entities in the definitions.
If the instances refer back to the same definition, then the last entity in the definition.entities is always going to be the same !
You assemble the array and only ever used the last entry !
I don’t see your logic…
Why not simply compare the instances definitions ?

As @eneroth3 has explained, your references @aa and @bb are referring to the exact same object.which is within the definition’s entities collection.
You refer to them as ‘instances’ but they are not - use puts @aa and puts @bb to see what is listed - it will be the same object from within the component definition - probably a Face or Edge, orperhaps a nested group or instance ??
You then refer to them as ‘components’ but they are not - they might be a component-instance located within the parent definition’s entities - but unless you print out [puts] the results for @aa and @bb we’ll never know.

Your references aa and bb on the other hand refer to two separate instances that can never be ==, but their definitions might be ==…

Perhaps we should ask you a basic question.
What is it that you are trying to do ?
I can not see any use in what you have shown us, so far…

Are you trying to determine the ‘parentage’ of a particular entity inside an instance of a definition ?
If so you probably need to use a Tool and/or pickhelper, do_pick and then get its path_at array [or leaf_at ?]…
That will include the particular instance in the array that is returned… it is not a simple exercise…

make the component “A”, and within the component “A” create a component “B”.
Copy component “A”.
With “==” compare two “A” components and you will get “false”.
Compare the two “B” components and you will get “true”.
Because “B” components are entities of “A” components that mutually have the same definitions I get both “B” as the one and the same object?

Instances are not parent components.
Instances do not “own” any geometry, only definitions do.
Therefore all instances of the same definition will have the exact same child elements.

It is incorrect to assume that instances will have unique child elements, because instances do not have an entities collection, only definitions do.

Okay! Thank you! I understand that component.definitions contain entities.
So if I have two component instaces that have the same definitions. If the first entity in the definitions of both components is a coponent instance, and if I compare these two components, I can not know whether I comparing the Component with herself or with another Component? There is no difference between them except that they are in the definitions of different component instances?

Definition … singular. The two instances have the same single definition.
Therefore all of the nested entities must be the same.

They MUST be the same object, and have it’s own definition that “owns” it’s own elements.

You continue to confuse yourself. The definition of the two instances is the same definition, therefore the geometry is the same, therefore the nested instance is the same instance in both.

Maybe a diagram will help?

Components.pdf (49.5 KB)


I get it! Thank you all for help!
Just one more question!
Is there a method that can find out how many copies of some entity exists in the model?
Something like count_equals or count_copies
I found .count_instances
Thank you all for once again!

This also count instances (in definitions that have no instances in the model.)

So also use Sketchup::ComponentDefinition#count_used_instances()

1 Like

At first I thought you meant that the nested component had the same definition as it’s parent component.

I was curious how SketchUp would react to that. Obviously that would == infinity which would cause SketchUp to crash so a nice little message is shown instead.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.