MEL How-To #28

Back · Previous · Next Maya

How do I query the tangent angles, weights and types for the keyframes on the object I'm animating?

OK, given that your object is "pSphere1" and the attribute you wish to query is ‘translateY’:

First, is ‘translateY’ animated?

connectionInfo -isDestination pSphere1.translateY
// Result: 1 //

Yes, it is. What's animating it?

connectionInfo -sourceFromDestination pSphere1.translateY
// Result: pSphere1_translateY.output //

Is 'pSphere1_translateY' an animCurve?

nodeType pSphere1_translateY;
// Result: animCurveTL //

Yes it is.

You want to go through all of this before querying keyframe stuff -- you can't rely that it will be an animCurve responsible for any animation.

So, given your animCurve is "pSphere1_translateY" and given that you're interested in a time value of 1.0:

Is there a keyframe at time 1.0?

keyframe -t "1.0:1.0" -q -keyframeCount pSphere1_translateY;
// Result: 1 //

Yes there is. If there wasn't a keyframe at the specified time, the next commands would return no values.

// First some shortcuts
string $animCurve = "pSphere1_translateY";
string $timeRange = "1.0:1.0";

// Variables to store the results
float $inTangent[], $outTangent[], $inWeight[], $outWeight[];
string $inTangentType[], $outTangentType[];

$inTangent = `keyTangent -t $timeRange -q -inAngle $animCurve`;
// Result: 45.290781 //

$outTangent = `keyTangent -t $timeRange -q -outAngle $animCurve`;
// Result: 45.29076 //

$inWeight = `keyTangent -t $timeRange -q -inWeight $animCurve`;
// Result: 1 //

$outWeight = `keyTangent -t $timeRange -q -outWeight $animCurve`;
// Result: 1 //

$inTangentType = `keyTangent -t $timeRange -q -inTangentType $animCurve`;
// Result: fixed //

$outTangentType = `keyTangent -t $timeRange -q -outTangentType $animCurve`;
// Result: fixed //

You could also omit the ‘−time’ option to get a list for all keys on the animCurve:

// First, determine which times have keyframes
keyframe -q -timeChange $animCurve;
// Result: 1 16 30 //

Now get the settings for each key, returned in an array where the order of the settings matches the time values from the array above.

$inTangent = `keyTangent -q -inAngle $animCurve`;
// Result: 45.290781 -41.692898 -61.0103 //
$outWeight = `keyTangent -q -outWeight $animCurve`;
// Result: 1 1 1 //
$outTangentType = `keyTangent -q -outTangentType $animCurve`;
// Result: fixed spline spline //