Maya 查找对象是否实例化?
Maya find if an object is instanced?
在 Maya 中,有没有办法通过脚本来确定对象是否是实例?到目前为止,我尝试过的所有技巧都不起作用。谢谢!
来自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:
instances.append(iterDag.fullPathName())
iterDag.next()
return instances
编辑:
我才意识到我并没有真正回答你的问题,只是给了你 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()
在脚本中:
def is_instanced(shape):
return len (cmds.listRelatives(shape, ap=True) or []) > 1
如果你有转换:
def is_instanced_xform(xform):
shape = cmds.listRelatives(xform, s=True)
if not shape:
return False
return len (cmds.listRelatives(shape, ap=True) or []) > 1
在 Maya 中,有没有办法通过脚本来确定对象是否是实例?到目前为止,我尝试过的所有技巧都不起作用。谢谢!
来自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:
instances.append(iterDag.fullPathName())
iterDag.next()
return instances
编辑:
我才意识到我并没有真正回答你的问题,只是给了你 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()
在脚本中:
def is_instanced(shape):
return len (cmds.listRelatives(shape, ap=True) or []) > 1
如果你有转换:
def is_instanced_xform(xform):
shape = cmds.listRelatives(xform, s=True)
if not shape:
return False
return len (cmds.listRelatives(shape, ap=True) or []) > 1