Does anyone know of a better way to do this? With the addition of animLayers (which are great) I haven’t found a simple maya command for finding the channel driven by an animation curve node. In the simplest situation, you used to be able to directly trace the curve’s output connection:
import maya.cmds as mc mc.listConnections('myAnimCurve.output', source=False, plugs=True)
Now with animLayers, there will be any number of nodes daisy-chained in-between the animCurve and the driven attribute, with different attributed names. Here’s how I’m currently handling that, though I’m not totally happy about it:
import maya.cmds as mc def _getChannelFromAnimCurve(curve): attr = '' if '.' in curve: curve, attr = curve.split('.') nodeType = mc.nodeType(curve) if nodeType.startswith('animCurveT') or nodeType.startswith('animBlendNode'): source = mc.listConnections(curve+'.output', source=False, plugs=True) if not source and nodeType=='animBlendNodeAdditiveRotation': #if we haven't found a connection from .output, then it may be a node that uses outputX, outputY, etc. #get the proper attribute by using the last letter of the input attribute, which should be X, Y, etc. source = mc.listConnections(curve+'.output'+attr[-1], source=False, plugs=True) if source: nodeType = mc.nodeType(source) if nodeType.startswith('animCurveT') or nodeType.startswith('animBlendNode'): return _getChannelFromAnimCurve(source) return source
Basically recursing through upstream connections and testing if we’re still looking at some sort of animCurve or animBlend node, until we find one that isn’t. It’s not very optimized, and it’s a bit sloppy with how it tests nodeType and constructs attributes, but it seems to work for the most part. I don’t totally trust it, though. For one, in the rare event that your driven channel is actually on a animCurve or animBlend node, it wont return it. If anyone has a more elegant solution, I’d be keen to hear it.