PDA

View Full Version : making UI, some queries are not working


Leionaaad
01-10-2009, 07:04 PM
I am trying to make some UI, first time doing that.
As an exercise, I wanted to make myself a small window, which creates utility nodes(I am a rigger, this kind of thing will come handy all the time). The problem arises, if I make a textfieldgroup, and I want to get the name from there. If I want to querry the text from the textfield, it says
"$baseName" is an undeclared variable.
I thought is because of the place I declared the variable. I tried to get the full path, to declare it before anything, asign it just after I put the textFieldGroup, nothing does it.

here is the code.

global proc utilWin(){
if(`window -exists "utilWin"`){
deleteUI -window "utilWin" ;
};

//layout
window -title "utility Creator" "utilWin" ;
columnLayout -width 318 -height 200 "mainLay" ;
frameLayout -collapsable false -width 318 -height 200 -borderVisible true -borderStyle "etchedIn" -marginWidth 6 -marginHeight 8 -label "NodeSetup" "nodeLay" ;
columnLayout "nodeSetup";
// fieldGroup
textFieldGrp -label "baseName" -columnWidth 1 64 -columnWidth 2 236 "nameAndLabel" ;
// utility buttons
rowColumnLayout -numberOfColumns 3 "buttons" ;
button -label "multiplyDivide" "mdBtn" ;
button -label "condition" "condBtn" ;
button -label "unitConversion" "ucBtn" ;
button -label "plusMinusAverage" "pmaBtn" ;
button -label "curveInfo" "ciBtn" ;
button -label "reverse" "revBtn" ;
button -label "distBetween" "distBtn" ;
button -label "setRange" "srBtn" ;
button -label "clamp" "cutBtn" ;
button -label "blendTwoAttr" "b2aBtn" ;
button -label "blendColors" "bcBtn" ;
button -label "vectorProduct" "vpBtn" ;
setParent.. ;
setParent.. ;
setParent.. ;
setParent..;
setParent.. ;
string $baseName = `textFieldGrp -q -text "nameAndLabel"` ;
button -edit -command "createNode multiplyDivide -n ($baseName + '_md_utl')" "mdBtn" ;
showWindow "utilWin" ;
window -edit -widthHeight 334 300 "utilWin" ;
}


Feel free to give advice to any other aspect, beside this problem I can't figure out.
Thank you.

YourDaftPunk
01-10-2009, 08:17 PM
What you needed to do was read the text field after the button was pressed. Here's a good way to do it:
proc createMultiplyDivideNode() {
string $baseName = `textFieldGrp -q -text "nameAndLabel"`;
createNode multiplyDivide -n ($baseName + "_md_utl");
}


global proc utilWin(){
if(`window -exists "utilWin"`){
deleteUI -window "utilWin" ;
};

//layout
window -title "utility Creator" "utilWin" ;
columnLayout -width 318 -height 200 "mainLay" ;
frameLayout -collapsable false -width 318 -height 200 -borderVisible true -borderStyle "etchedIn" -marginWidth 6 -marginHeight 8 -label "NodeSetup" "nodeLay" ;
columnLayout "nodeSetup";
// fieldGroup
textFieldGrp -label "baseName" -columnWidth 1 64 -columnWidth 2 236 "nameAndLabel" ;
// utility buttons
rowColumnLayout -numberOfColumns 3 "buttons" ;
button -label "multiplyDivide" "mdBtn" ;
button -label "condition" "condBtn" ;
button -label "unitConversion" "ucBtn" ;
button -label "plusMinusAverage" "pmaBtn" ;
button -label "curveInfo" "ciBtn" ;
button -label "reverse" "revBtn" ;
button -label "distBetween" "distBtn" ;
button -label "setRange" "srBtn" ;
button -label "clamp" "cutBtn" ;
button -label "blendTwoAttr" "b2aBtn" ;
button -label "blendColors" "bcBtn" ;
button -label "vectorProduct" "vpBtn" ;
setParent.. ;
setParent.. ;
setParent.. ;
setParent..;
setParent.. ;

button -edit -command "createMultiplyDivideNode" "mdBtn" ;
showWindow "utilWin" ;
window -edit -widthHeight 334 300 "utilWin" ;
}

I just changed your button command to: button -edit -command "createMultiplyDivideNode" "mdBtn" ; and had it call a new procedure- createMultiplyDivideNode. At that point the user has entered text so we can query the textFieldGrp and run createNode. Simple. Since your multiplyDivide node creation is now seperate, you can cleanly add some error checking into the code- did the user really enter a name? Does the node you are about to create already exist? If so, should your code rename it to prevent a collision or should you let the createNode command append a number to the name? It's up to you- either way, now you've got your interface separate from your logic, which is a very good thing.

-shawn

mlefevre
01-10-2009, 08:25 PM
Hey there,

I changed your code slightly. I'm not sure what your error was down to, perhaps it was when you were using the ' ' characters. I replaced them with \" instead.

I added a separate procedure that queries the textfield. It takes in two arguments, the name of the node your creating, and the suffix for that particular node. This way, you can place the two arguments in each button command, so you only need the one procedure.

Hope that helps,
Good luck!

-matt


*EDIT - daftPunk's beat me too it ;) hehe


global proc makeNode(string $node, string $suffix){

string $baseName = `textFieldGrp -q -text nameAndLabel`;
createNode $node -n ($baseName + $suffix);
};


global proc utilWin(){
if(`window -exists utilWin`)
deleteUI utilWin;

//layout
window -title "utility Creator" utilWin;
columnLayout -width 318 -height 200 "mainLay" ;
frameLayout -collapsable false -width 318 -height 200 -borderVisible true -borderStyle "etchedIn" -marginWidth 6 -marginHeight 8 -label "NodeSetup" "nodeLay" ;
columnLayout "nodeSetup";
// fieldGroup
textFieldGrp -label "baseName" -columnWidth 1 64 -columnWidth 2 236 "nameAndLabel" ;
// utility buttons
rowColumnLayout -numberOfColumns 3 "buttons" ;
button -label "multiplyDivide" -c "makeNode(\"multiplyDivide\", \"_md_utl\")" mdBtn;
button -label "condition" -c "makeNode(\"condition\", \"_cdn_utl\")" condBtn;
button -label "unitConversion" "ucBtn" ;
button -label "plusMinusAverage" "pmaBtn" ;
button -label "curveInfo" "ciBtn" ;
button -label "reverse" "revBtn" ;
button -label "distBetween" "distBtn" ;
button -label "setRange" "srBtn" ;
button -label "clamp" "cutBtn" ;
button -label "blendTwoAttr" "b2aBtn" ;
button -label "blendColors" "bcBtn" ;
button -label "vectorProduct" "vpBtn" ;
setParent.. ;
setParent.. ;
setParent.. ;
setParent..;
setParent.. ;

showWindow utilWin;

};

utilWin();

Leionaaad
01-10-2009, 08:31 PM
thank you people, now I got the general idea. :bounce:

CGTalk Moderation
01-10-2009, 08:31 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.