1

我可以用

hypershade -listUpstreamNodes

获取它们,但此命令在 Maya 批处理模式下不可用。我想我应该使用 MItDependencyGraph吗?有人可以给我一个简短的例子吗?谢谢 !

ps:我想在动画控件上找到所有动画曲线(它们可能在动画层中)。我可以使用的另一个地方是找到与给定网格关联的所有着色节点。我不想多次使用 listConnections 或 connectionInfo 并编写一个长函数来做到这一点。

4

2 回答 2

4

在香草玛雅蟒蛇

 import maya.cmds as cmds
 cmds.ls(*cmds.listHistory (mynode), type = 'animCurve' )

应该做同样的事情。在这两种情况下,您还必须寻找会出现在结果中的驱动键之类的东西。

于 2013-09-11T20:20:25.190 回答
2

在某处找到了一个很棒的例子....和一个很好的参考:introduction-to-the-maya-api

# Python code
import maya.OpenMaya as om

animCurves = []
# Create a MSelectionList with our selected items:
selList = om.MSelectionList()
om.MGlobal.getActiveSelectionList(selList)

# Create a selection list iterator for what we picked:
mItSelectionList = om.MItSelectionList(selList)
while not mItSelectionList.isDone():
    mObject = om.MObject()  # The current object
    mItSelectionList.getDependNode(mObject)
    # Create a dependency graph iterator for our current object:
    mItDependencyGraph = om.MItDependencyGraph(mObject,
                                               om.MItDependencyGraph.kUpstream,
                                               om.MItDependencyGraph.kPlugLevel)
    while not mItDependencyGraph.isDone():
        currentItem = mItDependencyGraph.currentItem()
        dependNodeFunc = om.MFnDependencyNode(currentItem)
        # See if the current item is an animCurve:
        if currentItem.hasFn(om.MFn.kAnimCurve):
            name = dependNodeFunc.name()
            animCurves.append(name)
        mItDependencyGraph.next()
    mItSelectionList.next()

# See what we found:
for ac in sorted(animCurves):
    print ac

修改的 :

def getAllDGNodes(inNode,direction,nodeMfnType):
    '''
    direction : om.MItDependencyGraph.kUpstream
    nodeMfnType : om.MFn.kAnimCurve
    '''    
    import maya.OpenMaya as om

    nodes = []
    # Create a MSelectionList with our selected items:
    selList = om.MSelectionList()
    selList.add(inNode)
    mObject = om.MObject()  # The current object
    selList.getDependNode( 0, mObject )

    # Create a dependency graph iterator for our current object:
    mItDependencyGraph = om.MItDependencyGraph(mObject,direction,om.MItDependencyGraph.kPlugLevel)
    while not mItDependencyGraph.isDone():
        currentItem = mItDependencyGraph.currentItem()
        dependNodeFunc = om.MFnDependencyNode(currentItem)
        # See if the current item is an animCurve:
        if currentItem.hasFn(nodeMfnType):
            name = dependNodeFunc.name()
            nodes.append(name)
        mItDependencyGraph.next()

    # See what we found:
    for n in sorted(nodes):
        print n

    return nodes
于 2013-09-11T10:14:11.787 回答