PDA

View Full Version : UI driving me insane


jgibz
12-23-2005, 05:05 PM
Hi all,

I've been tearing out my hair this morning over this.

global proc jgMakeRig()
{

//BUILD WINDOW
if(`window -exists jgWindow`)
deleteUI jgWindow;

string $jgMakeRigWindow = `window -title "jgMakeRig"
-widthHeight 483 203 jgWindow`;

rowLayout;

string $myTextField;

string $myCommand = "print(`textFieldButtonGrp -q -text $myTextField`)";

$myTextField = `textFieldButtonGrp
-label "test"
-text "test"
-buttonLabel "set"
-buttonCommand $myCommand`;

showWindow $jgMakeRigWindow;

}

after clicking the button:
// Error: print(`textFieldButtonGrp -q -text $myTextField`); //
// Error: "$myTextField" is an undeclared variable. //

any help would be great.

goleafsgo
12-23-2005, 05:47 PM
This has come up a few times this week....
The problem is that the variable $myTextField doesn't exist within the scope of the callback.
To try to understand this think of a global proc that looks like your callback. ie. like this..


global proc myButtonCommand()
{
print(`textFieldButtonGrp -q -text $myTextField`);
}

If you saw a proc like that it becomes obvious that that variable doesn't exist...but that's basically what Maya is executing when you click the button. It's a little less obvious because in your UI creation code the variable is right there...but it's not when it gets called later.

So one thing you can do is pass the actual name of the control to the callback and not the variable itself. You could get the name of the control when creating it and then edit the callback once you know what the name is like this...


global proc jgMakeRig()
{

//BUILD WINDOW
if(`window -exists jgWindow`)
deleteUI jgWindow;

string $jgMakeRigWindow = `window -title "jgMakeRig"
-widthHeight 483 203 jgWindow`;

rowLayout;

string $myTextField;

$myTextField = `textFieldButtonGrp
-label "test"
-text "test"
-buttonLabel "set"`;

string $myCommand = "print(`textFieldButtonGrp -q -text " + $myTextField + "`)";
textFieldButtonGrp -edit -buttonCommand $myCommand $myTextField;

showWindow $jgMakeRigWindow;
}

Notice that by appending the string variable on the end adds what the string is instead of adding the name of the variable.
There are probably a few ways that you can do this but that should get you going...

Pars
12-23-2005, 05:54 PM
Hi, i think the problem is due to that the text field group is only available in the scope of the procedure so after youve run the procedure it doesnt know what $myTextField is, thats just a guess tho. To get around it you can try this..

global proc jgMakeRig()
{

//BUILD WINDOW
if(`window -exists jgWindow`)
deleteUI jgWindow;

string $jgMakeRigWindow = `window -title "jgMakeRig"
-widthHeight 483 203 jgWindow`;

rowLayout;

string $myCommand = "print(`textFieldButtonGrp -q -text Ctlname`)";

string $myTextField = `textFieldButtonGrp
-label "test"
-text "test"
-buttonLabel "set"
-buttonCommand $myCommand Ctlname`;

showWindow $jgMakeRigWindow;

}

the string at the end of the textFieldButtonGrp acts as the controls name. hope this helps.

Edit: Damn seems someone beat me to the reply ;)

jgibz
12-23-2005, 08:13 PM
Thanks for the help guys, I tried both ways, both work :)

I settled on the former, just because I makes a bit more sense to me.

I knew there was somthing screwy with the variable scope, but I was copying this style from a book, so I guess the author is just on drugs.

hehe thanks.

CGTalk Moderation
12-23-2005, 08:13 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.