Maya for 3D Printing - Rapid Prototyping
In this course we're going to look at something a little different, creating technically accurate 3D printed parts.
# 1 05-04-2006 , 04:56 PM
Velusion's Avatar
Registered User
Join Date: May 2004
Location: Utah, USA
Posts: 369

Keyframe mel

I'm going to write a script that will be a great tool for animators but I could use a little guidance. Here's what I'm trying to do:

Imagine you're animating a character. Now, you're on frame 100 and you decide you want to turn the character's head. So, you turn its head BUT you are obligated to set a keyframe before frame 100 to serve as the start of the turn. Instead of going back in the timeline, wouldn't it be great if you could hit a button on a gui that would automatically set the keyframe for you. The gui could have a slider that allows you to set the number of frames back in time that the keyframe would be set. There could also be check boxes so you could tell it to set Trans X,Y,Z or Rot X,Y,Z.

I'm not trying to get anyone to write this script for me but if someone could point me toward the MEL commands that would most useful for this, I'd appreciate it. I'm not worried about the gui. I'm more concerned with the commands for going back in time and setting the keys.

Thanks a bunch!

# 2 05-04-2006 , 05:56 PM
skywola's Avatar
Registered User
Join Date: Jan 2004
Location: Tempe, Arizona, USA
Posts: 224
That's a great idea, I have some code in my Walkerman project that keyframes using MEL.

//Set KeyFrame

string $c = "setKeyframe " + $attr;

button -label "K" -annotation "Set Keyframe" -command $c;

// cut Keyframe

string $c = "cutKey -cl -t `currentTime -q` " + $attr;

button -label "U" -annotation "Cut Key" -command $c;


Would need to find a way to choose the frame being keyed, or temporarily change the frame back to the key point, key, then return.

I don't have the time now to do much more than post an example from the code I wrote, but I will take a look at it when I have more time this weekend. . .


"The Sage as an Astronomer: If you still see the stars as something above you, you lack the eye of knowledge." Friedrich Nietzsche
# 3 05-04-2006 , 08:59 PM
Velusion's Avatar
Registered User
Join Date: May 2004
Location: Utah, USA
Posts: 369
Much appreciated skywola.

I came up with this idea while animating since I am always forgetting to set a keyframe before repositioniing the model. All of a sudden you're scrubbing the timeline wondering why the models hand is going up and its head is turning user added image

# 4 06-04-2006 , 07:40 AM
skywola's Avatar
Registered User
Join Date: Jan 2004
Location: Tempe, Arizona, USA
Posts: 224
This one may be a little tricky because you would need to remember *NOT* to turn the head before you hit the "retro-key" button.

Perhaps a good solution would be have the code check for a keyframe occurence previous to the one you are attempting to place, then in the code, if there is none, have it set the pre-keyframe for the attribute you are attempting to set before it actually sets the one you are attempting to set.


"The Sage as an Astronomer: If you still see the stars as something above you, you lack the eye of knowledge." Friedrich Nietzsche
# 5 06-04-2006 , 12:39 PM
Velusion's Avatar
Registered User
Join Date: May 2004
Location: Utah, USA
Posts: 369
That's a very good idea.

# 6 06-04-2006 , 01:02 PM
skywola's Avatar
Registered User
Join Date: Jan 2004
Location: Tempe, Arizona, USA
Posts: 224
I know there is a way that Maya checks for previous keyframes, because you can actually click on a button next to the play buttons that will jump to the next or previous keyframes.

Turning "echo all commands" on, in the script editor gives me:

currentTime -edit `findKeyframe -timeSlider -which previous`;

when I click the go to previous key button . . .

That is probably a good hint on the direction you would want to go when writing the code to find if there is a previous keyframe.


"The Sage as an Astronomer: If you still see the stars as something above you, you lack the eye of knowledge." Friedrich Nietzsche
# 7 06-04-2006 , 02:32 PM
vladimirjp's Avatar
Subscriber
Join Date: Jun 2003
Location: stuck in the 90's boston, USA
Posts: 1,871

Re: Keyframe mel

Originally posted by Velusion


Imagine you're animating a character. Now, you're on frame 100 and you decide you want to turn the character's head. So, you turn its head BUT you are obligated to set a keyframe before frame 100 to serve as the start of the turn. Instead of going back in the timeline, wouldn't it be great if you could hit a button on a gui that would automatically set the keyframe for you.
I'm more concerned with the commands for going back in time and setting the keys.

Thanks a bunch!

just use autokey and in the prefs tell it to key all attributes instead of modified attributes.

remember u can simply mmb drag in the timeline while keeping a current frame, then simple press s or wiht suto key on with the right settings, just nudge the model; move rotate etc just slightly.
but mmb dragging the timeline is really faster and use auto key.
very simple imo.
no need for a mel here.

using your example of turning a heaed:

at frame 1 the head is at 0 but a 100 u want to turn the head to the right,
set your initial keyframe at frame 1 for ry to be 0, then just mmb drag to frame 99 and press s [or if u have autokey on, just nudge the head very slightly] then @ frame 100 just key the head turning. fastuser added image


Last edited by vladimirjp; 06-04-2006 at 02:34 PM.
# 8 06-04-2006 , 04:28 PM
Velusion's Avatar
Registered User
Join Date: May 2004
Location: Utah, USA
Posts: 369
Vlad, I agree with you. I think that I just got caught up in the challege posed by writing a script to do this simple task.


Last edited by Velusion; 06-04-2006 at 05:15 PM.
Posting Rules Forum Rules
You may not post new threads | You may not post replies | You may not post attachments | You may not edit your posts | BB code is On | Smilies are On | [IMG] code is On | HTML code is Off

Similar Threads