Home Technical Talk

[Maya Melscript GUI] - Displaying Text in a GUI Window?

StephenVyas
polycounter lvl 18
Offline / Send Message
StephenVyas polycounter lvl 18
Hi, 
I've created a simple Window GUI with one Button. 
When the button is pressed, I'd like it to display the name of the object I've selected in maya,  in a textfield within the GUI window. 

The text would be used as a confirmation that the user has selected that particular Object in the scene.



The Button function is called "returnIKcontroller". 
The returnIKcontroller() function returns the variable $name.

--------------------------------------------------------------------------------
string $name = "Nothing selected yet";

global proc string returnIKcontroller() {
   string $selected[] = `ls -sl`;
   string $name = $selected[0];
print ($name +" Selected\n");
return $name;
}
---------------------------------------------------------------------------------



Inside the window GUI creation, I've setup the code like this....

---------------------------------------------------------------------------------------
button -label "Select IK Controller" -command "returnIKcontroller";
                        textField -text $name;
----------------------------------------------------------------------------------------




Unfortunately, I can't seem to get the 'textfield $name' variable to update if the button is pressed with a different selection.


Is there a way to update the Window GUI to use the new variable?





Replies

  • GlowingPotato
    Options
    Offline / Send Message
    GlowingPotato polycounter lvl 10
    Hmmm...I think you can update using textfield and the flag -edit
    EDIT: yeah, I don't think you can update the button label directly. Maybe someone else knows.
  • StephenVyas
    Options
    Offline / Send Message
    StephenVyas polycounter lvl 18
    Yeah, I don't think Textfield is the right way to display a text prompt... 

    Maybe, Instead of the  textField -text $name;
    using...
    text -label $name;

    would be fine.. as long as I can find a way to update the $name variable
     
  • Klaudio2U
    Options
    Offline / Send Message
    Klaudio2U polycounter lvl 8
    I have made quick one using textFieldButtonGrp so perhaps it will help for what you want. What this one does is just returns selected object name in the text field when you press the button. Try it by making few primitives, select object and press button...should work.

    window;
    columnLayout;
    string $selObj[] = `ls -sl` ; textFieldButtonGrp -text $selObj[0] -buttonLabel "Button" -buttonCommand "objectName" selectedObject;

    proc objectName(){
    string $selObj[] = `ls -sl` ;
    textFieldButtonGrp -e -text $selObj[0] -buttonLabel "Button" -buttonCommand "objectName" selectedObject;
    }
    showWindow;

     If you want perhaps for the text field to auto update with whatever you have selected wihout need to always press the button to update field look at scriptJob command. Hope it helps.
  • StephenVyas
    Options
    Offline / Send Message
    StephenVyas polycounter lvl 18
    ahh Thanks so much Klaudio2u!!
    This place is never short of amazing people.
    Think i've been trying to teach myself Maya GUI since 7am this morning and getting nowhere with this.

    Your code is definitely the blue print for what I'm after. Thanks again!!
Sign In or Register to comment.