Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

Get AnimCurve on the object with the attribute from the Animlayer

Get AnimCurve on the object with the attribute from the Animlayer

Anonymous
Not applicable
953 Views
1 Reply
Message 1 of 2

Get AnimCurve on the object with the attribute from the Animlayer

Anonymous
Not applicable

For get AnimCurve on the object with the attribute from the Animlayer we need:

1 - select the layer from which you want to get the AnimCurve (BaseAnimation or another)

2 - run Mel or cmds script

*Note - you only need to select one layer, so only one layer should have "selected" and "preferred" attributes activated

nodeName = ["locator1.rx"]
currentLayerSpecifiedAnimCurve = cmds.keyframe( nodeName, query=True, name=True )
print( currentLayerSpecifiedAnimCurve )
#['locator1_rotate_AnimLayer2_inputBX']

 

But what if we want use OpenMaya for this case

OpenMaya have "MAnimUtil.findAnimation" method, but it return for MPlug "locator1.rx" AnimCurves from all dependend layers, also it return rotateY and rotateZ AnimCurves

nodeName = "locator1"
mSelectionList = OpenMaya.MSelectionList()
mSelectionList.add( nodeName )
nodeMObject = mSelectionList.getDependNode( 0 )
nodeMPlug = OpenMaya.MFnDependencyNode( nodeMObject ).findPlug( "rx", False )
animCurvesMObjectArray = OpenMayaAnim.MAnimUtil.findAnimation( nodeMPlug )

for i in range( animCurvesMObjectArray.__len__() 😞 
    print( OpenMaya.MFnDependencyNode( animCurvesMObjectArray[i] ).name() )	

#locator1_rotate_AnimLayer1_inputBX
#locator1_rotate_AnimLayer1_inputBY
#locator1_rotate_AnimLayer1_inputBZ
#locator1_rotateX
#locator1_rotateY
#locator1_rotateZ
#locator1_rotate_AnimLayer2_inputBX
#locator1_rotate_AnimLayer2_inputBY
#locator1_rotate_AnimLayer2_inputBZ

 

Also OpenMaya have "OpenMaya.MItDependencyGraph", but result the save as we get from "findAnimation"

nodeName = "locator1"
mSelectionList = OpenMaya.MSelectionList()
mSelectionList.add( nodeName )
nodeMObject = mSelectionList.getDependNode( 0 )
nodeMPlug = OpenMaya.MFnDependencyNode( nodeMObject ).findPlug( "rx", False )

mItDependencyGraph = OpenMaya.MItDependencyGraph( nodeMObject,
                                           OpenMaya.MFn.kAnimCurve, 
                                           OpenMaya.MItDependencyGraph.kUpstream,
                                           OpenMaya.MItDependencyGraph.kBreadthFirst,
                                           OpenMaya.MItDependencyGraph.kNodeLevel,
                                           OpenMaya.MItDependencyGraph.kDependsOn)
                                           
mItDependencyGraph.resetTo( nodeMPlug,
                            OpenMaya.MFn.kAnimCurve, 
                            OpenMaya.MItDependencyGraph.kUpstream,
                            OpenMaya.MItDependencyGraph.kDepthFirst,
                            OpenMaya.MItDependencyGraph.kPlugLevel, 
                            OpenMaya.MItDependencyGraph.kDependsOn )
            
while not mItDependencyGraph.isDone():
    currentNodeMObject = mItDependencyGraph.currentNode()
    depNode = OpenMaya.MFnDependencyNode( currentNodeMObject )
    depNodeName = depNode.name()
    print( depNodeName )
    mItDependencyGraph.next()

#locator1_rotateX
#locator1_rotateY
#locator1_rotateZ
#locator1_rotate_AnimLayer2_inputBX
#locator1_rotate_AnimLayer2_inputBY
#locator1_rotate_AnimLayer2_inputBZ
#locator1_rotate_AnimLayer1_inputBX
#locator1_rotate_AnimLayer1_inputBY
#locator1_rotate_AnimLayer1_inputBZ

 

So what way, if it exist, by OpenMaya, get result life by Mel or cmds method?

 

0 Likes
954 Views
1 Reply
Reply (1)
Message 2 of 2

MoneySD8VY
Community Visitor
Community Visitor

I'd say you're on the right track. Start with whichever method you prefer from the above to get all those animCurves, then do another filter and look for the animation layer you want to work with within the list of all those animation curves, and if you only want specific axis, do another filter looking for that specific axis with what's left and you should get it!

0 Likes