Python Forum

Full Version: how to call an object in another function in Maya
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have a UI to set the color of the controls of the autorig. When I connect the button to a function I run into a problem. The called function can't find the button that calls it.

# Error: RuntimeError: file <maya console> line 194: Object 'colorChoice' not found. #

If I put the function in the same script I get a problem because It can't query the button before the button has been created.
If I put the function in the same script after the button is created it doesn;t work because the script is being called before the script has been defined.

How do I resolve this flow of information? Is there a good tutorial for accessing objects created in another function?

Thanks for your help.

def test4():    
        
    WindowID = 'test'
        
    if cmds.window (WindowID, exists = 1):
        cmds.deleteUI(WindowID)

    cmds.window(WindowID, resizeToFitChildren = 1)
    cmds.frameLayout( label='Choose colors' )
    cmds.columnLayout()
    cmds.text('Choose the color of the controls')
    cmds.radioButtonGrp('colorChoice,' "Analyse_btw", labelArray3=['All one Color', 'Red/Blue/Green', 'Purple/Orange/Yellow' ], numberOfRadioButtons=3 , sl= 2, cc= setControlColors())
    cmds.showWindow()
    

def setControlColors():
    controlColorChoice = cmds.radioButtonGrp('colorChoice', q=1,sl=1)