Maya查找对象是否已实例化?

Gre*_*ell 2 python maya

在Maya中,有没有办法通过脚本来查明对象是否是实例?到目前为止我尝试的每一个技巧都不起作用.谢谢!

DrH*_*aze 5

来源:

# 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:
            instances.append(iterDag.fullPathName())
        iterDag.next()
    return instances
Run Code Online (Sandbox Code Playgroud)

编辑:

我刚刚意识到我并没有真正回答你的问题而只是给你Maya场景中的所有实例.

以下是您可以用来检查节点是否是实例的其他代码:

def pathToDagNode( fullPath ):
    if not cmds.objExists(fullPath):
        return None
    else:
        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()
Run Code Online (Sandbox Code Playgroud)