Search code examples
pythonmaya

Passing the name of radio button in maya/python


How do you get the label/value of a radioButton in python? Can't find any good info on such a simple thing.

#radioButtons
cmds.radioButton(l="Circle", select=True)
cmds.radioButton(l='Triangle')
cmds.radioButton(l='Square' )

When i try use a value of a selected radioButton i can't because I keep getting "radioButton539" and it changes every time i run the code.


Solution

  • Indeed, without any name, maya automatically names the UI elements. To name the UI element you usually do it with the first argument:

    theName = "MyRadioButtonName"
    cmds.radioButton(theName, l="Circle", select=True)
    

    But you have to be careful because if the UI element aready exists, you will get another name. The best way is to use the name the way it is returned from the command:

    theName = "MyRadioButtonName"
    theButton = cmds.radioButton(theName, l="Circle", select=True)
    ...
    label = cmds.radioButton(theButton, q=True, l=True)