View Full Version : Changing timeslider in Graph Editor

01 January 2011, 12:40 PM
Hey all,

Im trying to write a little script that means that when I select a key in the graph editor the time automatically updates to that frame so I can see my adjustments in the persp. At the moment when animating each time I adjust a key in the graph editor I have to also move the timeslider onto that frame so I can actually see my changes. I have -

import maya.cmds as cmds frame = cmds.keyframe( q=True, sl=True, tc=True);
cmds.currentTime( frame[1] );

I need this to do it everytime I select a key. At the moment I have to run it everytime which completely take the point out of it. How do I get this to run in the background constantly?

Does that make sense? Probably a noob question I know.


01 January 2011, 02:36 PM
if you wanted to auto-run something everytime you made a selection change you need to wrap it up in a scriptJob. You'll also need to put a little more error checking in your code too, as afaik there's no separate scriptJob event to distinguish between normal node selection and keyframe selection.
scriptJob -event "SelectionChanged" "runThisFunc";:nathaN

01 January 2011, 12:03 AM
Cheers for the point in the direction Nathan. scriptJob was just what I was looking for :)

Managed to get the script working quite nicely in the end with it selecting the middle frame if you select various at once.

global proc jumpToFrame() {
float $frames[] = `keyframe -animation "keys" -q -sl`;
if ( $frames[0] > 0 ) {
$size = 0;
$sum = 0;
for( $i in $frames )
$sum += $i;
$size += 1;
$average = $sum / $size;
currentTime $average;
scriptJob -event "SelectionChanged" "jumpToFrame";

Thanks again! Sim

01 January 2011, 10:32 PM
I usually hold "k" and click at whatever key I'm currently editing.

CGTalk Moderation
01 January 2011, 10:32 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.