Python Forum
how to call an object in another function in Maya
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to call an object in another function in Maya
#1
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)
Larz60+ write Apr-05-2021, 10:18 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.

Fixed for you this time. Please use bbcode tags on future posts.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How do I call sys.argv list inside a function, from the CLI? billykid999 3 788 May-02-2023, 08:40 AM
Last Post: Gribouillis
  cx_oracle Error - AttributeError: 'function' object has no attribute 'cursor' birajdarmm 1 2,332 Apr-15-2023, 05:17 PM
Last Post: deanhystad
  AttributeError: 'function' object has no attribute 'metadata 3lnyn0 5 4,597 Mar-28-2022, 04:42 PM
Last Post: Larz60+
  'int' object is not subscriptable after API call ed8484 1 1,807 Sep-18-2021, 02:06 PM
Last Post: ed8484
  In this function y initially has no value, but a call to foo() gives no error. Why? Pedroski55 8 3,469 Dec-19-2020, 07:30 AM
Last Post: ndc85430
  Struggling for the past hour to define function and call it back godlyredwall 2 2,209 Oct-29-2020, 02:45 PM
Last Post: deanhystad
  list call problem in generator function using iteration and recursive calls postta 1 1,895 Oct-24-2020, 09:33 PM
Last Post: bowlofred
  function call at defined system time? Holon 5 3,221 Oct-06-2020, 03:58 PM
Last Post: snippsat
  subprogram issues: cannot unpack non-iterable function object error djwilson0495 13 5,976 Aug-20-2020, 05:53 PM
Last Post: deanhystad
  How to call/read function for all elements in my list in python johnny_sav1992 1 2,073 Jul-27-2020, 04:19 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020