Green Cell Green Cell - 6 months ago 49
Python Question

Maya find if an object is instanced?

In Maya, is there a way via script to find out if an object is an instance or not? Every trick I've tried so far isn't working. Thank you!


From source:

# Python code
import maya.OpenMaya as om

def getInstances():
    instances = []
    iterDag = om.MItDag(om.MItDag.kBreadthFirst)
    while not iterDag.isDone():
        instanced = om.MItDag.isInstanced(iterDag)
        if instanced:
    return instances


I just realized I wasn't really answering your question and just giving you all the instances in your Maya scene.

Here is an other code you can use to check if a node is an instance :

def pathToDagNode( fullPath ):
    if not cmds.objExists(fullPath):
        return None
        selectionList = om.MSelectionList()
        selectionList.add( fullPath )
        dagPath = om.MDagPath()
        selectionList.getDagPath( 0, dagPath )
        return dagPath

dag_node = pathToDagNode( '|your|node|full|path' )
print dag_node.isInstanced()