PDA

View Full Version : creating setKeyframe button


Luddy
05-07-2003, 05: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.

michaelcomet
05-07-2003, 07: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.

ie:



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

OR:

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

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

Luddy
05-07-2003, 08: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");

michaelcomet
05-07-2003, 09:01 PM
yes

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

looks correct to me.

Luddy
05-07-2003, 09: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?

michaelcomet
05-07-2003, 09: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.

This:

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.

Luddy
05-07-2003, 10: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-15-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.