View Full Version : query the value in textfield?

10 October 2005, 01:54 PM
Hi I'm trying to figure out how to query the value in a textfield
when a button is pressed, my proc code is incorrect but I'm not sure how to fix it

here's the code

//window check
if(`window -exists $winName`)
deleteUI -window $myWindow;

//window creation here
string $winName = "ProCam";
string $myWindow= `window -title "Pro Camera Setup"
-w 225 -h 100 -s 1 -mnb 1 -mxb 0

//window layout
string $form = `formLayout -nd 225 myform`;
string $labl= `text -label "Camera Name"`;
string $cameraName = `textField -w 100`;
string $butn = `button -label "Create Camera" -c "Values" mybutton`;

//controls for windows here
formLayout -e -af $labl "top" 10 myform;
formLayout -e -af $cameraName "top" 8 myform;
formLayout -e -af $cameraName "left" 70 myform;
formLayout -e -af $butn "top" 30 myform;

proc Values()
textField -q -tx $cameraName;
print $cameraName

showWindow $winName;

Thanks for all your help,

10 October 2005, 06:45 PM
I don't have maya handy, so take this with a grain of salt.

This line:
string $cameraName = `textField -w 100`;

is telling $cameraName to be the result of `textField -w 100`...which I am guessing is not a node.
I believe the last argument to a textField is a varible that gets filled with the textFiled node, try that instead.

I think it's this (without checking in Maya):
string $tField;

// in creation of window...
textField -w 100 $tField;

// later on in program
textField -q -text $tField

My syntax is probably wrong, and there will probably be 12 posters after me explaining the proper syntax...but I believe the concept is valid.


10 October 2005, 08:20 PM
You need to pass the string to the proc because it's not a global string. This is the proc I use to query a textfield.

proc string getTextfieldData(string $textField)
string $filePath= `textField -q -tx $textField`;
return $filePath;

here is a proc that calls the getTextfieldData proc.

proc writeFile()
string $layoutName = `getTextfieldData "textFieldName"`;
string $filePath = `getTextfieldData "textFieldDir"`;
kf_writeLayout ($filePath + $layoutName+ ".txt");


Hope you find this useful


10 October 2005, 10:40 PM
Alternatively, you can explicitly name the control upon creation, like this:

textField -w 100 cameraNameTxtField;

By doing this you get two things. You always know the name of the control, since you named it, and as long as the window is open, you can always query the control by name, like so:

textField -q -text cameraNameTxtField;

This eliminates the need for either casting the result of the creation of the control to a variable, and/or the need for global variables if you want to query the control from another procedure.

This is easiest as long as the window layout is simple, which is usually the case. For more advanced window layouts (i.e layouts parented to layouts), you will either need to march the hierarchy of the window layouts, or use variables to hold the names and pass the contents of the variables between procedures. In advanced layouts, I opt for passing the information around.

CGTalk Moderation
10 October 2005, 10:40 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.