I can use
hypershade -listUpstreamNodes
to get them, but this command is not available in maya batch mode.
i guess i should use MItDependencyGraph ? can someone give me a short example ? thanks !
ps: i want to find all anim curves on anim controls( they may be in anim layers). another place i can use this is find all shading nodes associated with a given mesh. i don't want to use listConnections or connectionInfo multiple times and write a long function to do it.
in vanilla maya python
import maya.cmds as cmds
cmds.ls(*cmds.listHistory (mynode), type = 'animCurve' )
Should do the same thing. In both cases you'll also have to look for things like driven keys that will show up in the results.
found an awesome example somewhere ....
and a great reference : 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
modified :
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