PDA

View Full Version : Animation MEL masters! Save keys to open doors!


Dreppan
04-26-2006, 06:38 PM
Is there a script to find the last keyframe of any hierarchy -- whether it's a jointed skeleton or a constraint system on a rig? I would like to set the current timeline of characters that are read in to always reflect the length of their animation.

The reason it seems trickier with a hierarchy is that the last keyframe may not be on the top node or joint, but hidden within the hierarchy on a toe or finger constraint/joint.

Rig Example: The top constraint has an animation from frames 1 - 40, but the furthest keyframe in the hierarchy is the toe controller animation, which goes to 45. I would want the script to find this, and automatically set the Maya timeline to 1 - 45.

Any help is appreciated -- thanks ahead of time.

john_homer
04-26-2006, 10:46 PM
select a hierarchy (or more)...

string $sel[] = `ls -sl`;
string $allDecendants[] = `listRelatives -f -ad $sel`;
string $allObjects[] = stringArrayCatenate($sel, $allDecendants);
float $lastKey = -98989898989;
for ($c in $allObjects)
{
string $allAttrs[] = `listAnimatable $c`;
for ($attr in $allAttrs)
{
float $keyLst[] = `keyframe -q -tc $attr`;
if (size($keyLst) > 0)
{
if ($keyLst[(size($keyLst))-1] > $lastKey)
$lastKey = $keyLst[(size($keyLst))-1];
}
}
}

print ("last keyframe is " + $lastKey);

Dreppan
04-27-2006, 01:29 PM
Lovely. This is perfect -- thanks! Is there a way to determine the first frame of said animation as well?

CGTalk Moderation
04-27-2006, 01:29 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.