MEL How-To #84 | ||
| ||
How do I query which keyframes are selected in the Graph Editor or Dope Sheet?To get the selected curves and keys you can use the ‘
// Selected animCurve(s)
string $animCurves[] = `keyframe -q -name`;
// Result: pSphere1_translateX //
An animCurve may be feeding more than one node/channel/whatever in Maya. You can determine its effect by finding its downstream connections: string $effects[] = `listConnections -plugs true $animCurves[0]`; // Result: pSphere1.translateX // To determine the values for the key, use the ‘ // Here I've selected the entire curve: float $selectTimes[] = `keyframe -q -sl -timeChange $animCurves[0]`; // Result: 1 60 // float $selectValues[] = `keyframe -q -sl -valueChange $animCurves[0]`; // Result: 0 0.5 // // And here I've selected the key at frame 60: float $selectTimes[] = `keyframe -q -sl -timeChange $animCurves[0]`; // Result: 60 // float $selectValues[] = `keyframe -q -sl -valueChange $animCurves[0]`; // Result: 0.5 // Note in the examples above how the Consider the following Graph Editor where I've selected the keys at frame 60 for all three translation curves. string $animCurves[] = `keyframe -q -sl -name`; // Result: pSphere1_translateX pSphere1_translateY pSphere1_translateZ // keyframe -q -sl -vc; // Result: 1 1 1 // keyframe -q -sl -tc; // Result: 60 60 60 // This wouldn't do you much good if you were looking to modify a key at a particular frame. However, you can isolate the key and time values by querying on individual curves. keyframe -q -sl -vc pSphere1_translateY; // or $animCurves[1] from above // Result: 1 // keyframe -q -sl -tc pSphere1_translateY; // or $animCurves[1] from above // Result: 60 // Editing the selected key is a bit more involved. You need to edit the key by its index, but you cannot query the selected index. Thus, you must query the selected time/value, iterate the curve looking for said key, then write. Here is where it becomes necessary to specify the target animCurve, so as to avoid modifying a key an identical time or value, but on a curve animating a different channel.
float $allTimes[] = `keyframe -q -timeChange $animCurves[0]`;
float $allValues[] = `keyframe -q -valueChange $animCurves[0]`;
// Set selected key value to 0.2
for ( $i = 0; $i < `size $allTimes`; $i++ )
{
if ( ( $allTimes[$i] == $selectTime[0] ) &&
( $allValues[$i] == $selectValue[0] ) )
{
keyframe -e -index $i -valueChange 0.2 $animCurves[0];
}
}
In summary, use ‘ Related How-To's | ||
Copyright ©2005 by Bryan Ewert, maya@ewertb.com Maya is a Registered Trademark of Alias |