How can you tell if an object is an instance?

How can you tell if an object is an instance?

Anonymous
Not applicable
7,452 Views
12 Replies
Message 1 of 13

How can you tell if an object is an instance?

Anonymous
Not applicable

Pretty much what the title asks. I need to be able to distinguish an original object from an instanced one. No, I don't think layers it the solution here, as I would rather check the object itself as the source-of-truth.

0 Likes
Accepted solutions (2)
7,453 Views
12 Replies
Replies (12)
Message 2 of 13

djonesuk
Advocate
Advocate

I'd be interested in opinions on this matter but I'm not sure there is such thing as an 'original' or 'instance'.  They are just transform nodes with the same shape node attached.  As far as I can tell, only the name would give an indication of which was created first.  In fact, if you convert instances back into objects, it's possible for one of the non-original instance objects to get the construction history.

 

2017-07-14 18_44_40-Node Editor.png

 

 

 

 

Message 3 of 13

mspeer
Consultant
Consultant

Hi!

 

There is no difference between an instance and the original object, they have different transforms but they point to the same mesh/shape.

Therefore if you have 2 objects ( one is the original and one the copied instance) and you only want to keep 1 object it doesn't matter which one you delete. Also if you want to make changes to an object it doesn't matter which instance you choose.

Message 4 of 13

Anonymous
Not applicable

@mspeer wrote:

 

Also if you want to make changes to an object it doesn't matter which instance you choose.


Hi mspeer,

 

Thank you for the reply! I think it may help if I clarify the question. How can I tell if an object is an instance, as opposed to a duplicate?

 

Let's say I add a cube to the scene and make a duplicate of it. I then also make another special duplicate (instance) of it. How do I tell by looking at the two new cubes' attributes, whether one is an instance or a duplicate? Especially in a scene with hundreds of objects.

 

In the outliner hierarchy, the original cube, the duplicate and the instance all look identical.

0 Likes
Message 5 of 13

mspeer
Consultant
Consultant
Accepted solution

Hi!

 

Again, there is no difference except that instances share the same mesh, so just compare the name of the transform node with the name of the shape node.

 

Select the Shape (not the transform) and all instances will highlight in Viewport, or if all Instances share the same Material you could select by Material.

You may also check if a Shape is assigned to multiple transforms with MEL.

0 Likes
Message 6 of 13

djonesuk
Advocate
Advocate
Accepted solution

You would have to use a MEL script to, for example, set the outliner colour.

 

$selection = `ls -sl`;
for ($object in $selection) {
    string $children[] = `listRelatives -fullPath -children $object`;
    string $parents[] = `listRelatives -fullPath -allParents $children[0]`;
    float $outlinerColorR = 0, $outlinerColorG = 1, $outlinerColorB = 0;
    
    if (size($parents) > 1) {
        //print($object + " is instance!\n");
        setAttr ($object + ".useOutlinerColor") 1;
        setAttr ($object + ".outlinerColor") $outlinerColorR $outlinerColorG $outlinerColorB;
    }
}
Message 7 of 13

absoluteKelvin
Collaborator
Collaborator

very handy script djonesuk

https://www.artstation.com/kelvintam
0 Likes
Message 8 of 13

malcolm_341
Collaborator
Collaborator

@djonesuk This is a great script, thanks for sharing.

0 Likes
Message 9 of 13

ayushbakshi98
Enthusiast
Enthusiast

Hey, You can have this info displayed in the HUD of viewport by doing this. 

Menu Bar → Display → Heads Up Display → Object Details

Message 10 of 13

malcolm_341
Collaborator
Collaborator

@ayushbakshi98 Any idea what the Maya internal code is that queries if it's an instance or not for the HUD, or which Mel file I could find that info in?

0 Likes
Message 11 of 13

ayushbakshi98
Enthusiast
Enthusiast

Yes,  A little bit.
Here's the mel command that, I think, tells the HUD if the selection is instance or not

objectDetailsInstance();

 

Some other python commands that might help to deal with instances:

https://help.autodesk.com/cloudhelp/2024/ENU/Maya-Tech-Docs/CommandsPython/filterInstances.html

https://help.autodesk.com/cloudhelp/2024/ENU/Maya-Tech-Docs/CommandsPython/instanceable.html

Message 12 of 13

malcolm_341
Collaborator
Collaborator

@ayushbakshi98 Well, that solves it. Nice work, here's the code to test if the selected object is an instance.

 

string $instanceTrue = objectDetailsInstance();

if ($instanceTrue == "Yes")
{
	print "This is an instance\n";
}
else
{
	print "This is not an instance\n";
}
Message 13 of 13

MaYa_people
Contributor
Contributor

This post seems old, but I think many people have this need. There are many instances of different objects in my scene. I need to get all the instanced objects by selecting one of them. My idea is to use the same shape nodes between instanced objects to reversely find their transformation nodes.

0 Likes