Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

User Input from Textfield problem

User Input from Textfield problem

peter_baehr97
Contributor Contributor
414 Views
4 Replies
Message 1 of 5

User Input from Textfield problem

peter_baehr97
Contributor
Contributor

Hi!

 

The script is supposed to do the following:

1. open a window with 1 button and 1 textfield

2. when the button is pressed i want to create a nurbs circle that is named according to what was typed into the textfield.

 

When executing the script i get an error saying:

"Error: Line 20.24: "$ctrlName" is an undeclared variable."

 

This is my script:

//Window creation
if ( `window -exists MyRigging` )
{
deleteUI MyRigging;
}
window -wh 300 500 MyRigging;
//

columnLayout;

string $ctrlName;
text -label "Enter Control Name";
textField -w 100 $ctrlName;

//Button and Procedure:
button -w 110 -h 35 -l "Create FK Control" -command "createFK()" MyButton1;

proc createFK()
{
circle -n $ctrlName;

}
//
//Show the final window
showWindow MyRigging;
//

 

The problem of the script seems to be that the procedure createFK is not able to call the $ctrlName string. But I am absolutely clueless how i would do that.

 

Greatly appreciate any help!

0 Likes
Accepted solutions (3)
415 Views
4 Replies
Replies (4)
Message 2 of 5

Kahylan
Advisor
Advisor
Accepted solution

Hi!

 

If you want to define your variable outside of a procedure, you need to make it global and call it inside the procedure so you can use it.

Also you need to fetch the value of the Textfield before you create the circle, maya doesn't do that automatically on edit (as far as I know)

 

//Window creation
if ( `window -exists MyRigging` )
{
deleteUI MyRigging;
}
window -wh 300 500 MyRigging;
//

columnLayout;

global string $ctrlName;
text -label "Enter Control Name";
textField -w 100 $ctrlName;

//Button and Procedure:
button -w 110 -h 35 -l "Create FK Control" -command "createFK()" MyButton1;

proc createFK()
{
global string $ctrlName;
string $name = `textField -q -text $ctrlName`;
circle -n $name;

}
//
//Show the final window
showWindow MyRigging;
//

 

I hope this helps!

Message 3 of 5

peter_baehr97
Contributor
Contributor
Accepted solution

Thanks for the quick help! It seems to solve the variable issue, but now I get a new Error when pressing the button, which is just saying:

// Error: line 21: Object '' not found. //

 

So there seems to be a problem in the line:

string $name = `textField -q -text $ctrlName`;

 

I can't really see whats the problem. Appreciate any help!

 

0 Likes
Message 4 of 5

Kahylan
Advisor
Advisor
Accepted solution

I wasn't sure if that was going to cause a problem, since MEL has the great feature to not empty/redefine stored variables during an ongoing session. /s

Just add a random string into the first definition of $ctrlName, for example:

global string $ctrlName = "CTRL";

I changed that during testing and then changed it back because I wasn't sure if it is necessary, and the documentation said it wasn't...

For some reason the textField wants a default value in order to let you change it after, I'm not quite sure why... But that should fix the problem.

Message 5 of 5

peter_baehr97
Contributor
Contributor

Big Thanks for the reply!! Script is finally working correctly.