View Full Version : creating setKeyframe button

05 May 2003, 04:15 PM
I'm creating a key button for a joints.rx. When I press the button the variable $keyJoint is said to be undeclared. I can't directly enter in the joint name because the variable after the underscore changes. Is the command written another way?

//$input = `textField -query -tx "renTextField"`; // =1, 5 etc.

string $keyJoint = "joint_" + $input + ".rx";
button -w 40 -h 17 -l "key" -c "setKeyframe $keyJoint";


global proc string newName (string $input)
$input = `textField -query -tx "renTextField"`;
string $keyJoint = "joint_" + $input + ".rx";
return $keyJoint;
$keyJoint = `newName $input`
newName $input;

Also, how do you default the textField at "1" when the window opens? It currently opens blank.

05 May 2003, 06:13 PM
You either need to make your variable global, and declare it that way in the -c or better just code it to do a query on the button press.


string $keyJoint = "joint_" + $input + ".rx";
button -w 40 -h 17 -l "key" -c ("setKeyframe "+$keyJoint);


button -w 40 -h 17 -l "key" -c (" doIt(); ");

global proc doIt()
string $keyJoint = newName("") ;
setKeyframe $keyJoint ;

05 May 2003, 07:56 PM
Thanks michaelcomet, I think I can get it to work this way though...

When the button's command is ($skullJoints[0]+".rx")
I get the error "joint_1" proc not found, of course.

How do you write the command with setKeyframe before the name $skullJoint[0]+".rx"?

string $skullJoints[] = `ls -sl`;

button -w 40 -h 17 -l "key" -c ("setKeyframe "+$skullJoints[0]+".rx"); // ??

When the button is pressed nothing happens
The Slider works fine.
attrFieldSliderGrp -label "Skull LeftRight" -min -20 -max 20 -at ($skullJoints[0]+".rx");

05 May 2003, 08:01 PM

button -w 40 -h 17 -l "key" -c ("setKeyframe "+$skullJoints[0]+".rx");

looks correct to me.

05 May 2003, 08:12 PM
Hmm. :hmm:

(setKeyframe ($skullJoints[0]+".rx")); //syntax error
("setKeyframe "+$skullJoints[0]+".rx"); //does nothing
($skullJoints[0]+".rx"); // Cannot find procedure "joint_1.rx".

Should the setKeyframe command recognize the variable when the button is pressed?

05 May 2003, 08:39 PM
Without seeing the entire code, this is hard to explain.

But no this:

(setKeyframe ($skullJoints[0]+".rx")); //syntax error

won't work and WILL give a syntax error, unless teh variable is defined at that point in time. ie: unlesss you have decalred $skullJoints either globally, or just before the command, inside of the code block you are working on.


eval("setKeyframe "+$skullJoints[0]+".rx"); //does nothing

will work assuming that $skullJoints[0] IS defined to something ahead of time when this line is executed

Note i added "eval" in front. If you just have the line, then you are just defining a string.

All the "-c" does is take a string that later gets executed. For example:

string $skullJoints[] = `ls -sl`;

string $cmd = ("setKeyframe "+$skullJoints[0]+".rx") ;

print ("// DEBUG: Command IS: "+$cmd+" //\n");

button -w 40 -h 17 -l "key" -c $cmd -ann $cmd;

should create a button that will key the rotateX channel of the 1st selected object. You MUST have an object selected at the time this UI is opened/created of course for this to work.

Instead of a button you could do an eval to test it. I just did and it works fine.

Note I also set the button -ann for annotation to the command, so you can see what will get executes if you put your mouse over it.

Note this code Will NOT make the button key any selected object. Only the one that was selected when the UI was built. If you need to key any object currently selected, then you'd need to make the button call a procedure, that in the proc did a new ls -sl` and then a new key... or just called setKeyframe -at "rotateX" which will auto key that at for any selected objects anyhow.

05 May 2003, 09:23 PM
Great! It works.

I had to break my procedure into two and declare the array as global.

Thanks for the help, and thanks to all the others who've helped me the past week. :beer:

CGTalk Moderation
01 January 2006, 03:00 AM
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.