script flow question

script flow question

Anonymous
Not applicable
445 Views
1 Reply
Message 1 of 2

script flow question

Anonymous
Not applicable

When I enter the code into the script editor highlight it and hit (ctrl, enter) the window calls the functions "red", "blue" etc.  just fine. But when I call is as a module the buttons give me an error message " # NameError: name 'red' is not defined #". I think I'm using the same format that successfully calls other modules and functions but obviously something is awry. I have tried it with and without *args in the parentheses for the color functions (red(), red(*args)) with no difference.

def red(*args):
    print('red')

def orange(*args):
    print('orange')

def yellow(*args):
    print('yellow')

def green(*args):
    print('green')        

def blue(*args):
    print('blue')

def indigo(*args):
    print('indigo')

def violet(*args):
    print('violet')


import maya.cmds as cmds

def colorControls(): 
    print('controls are all one color')
        
    if cmds.window ('ColorChooser', exists = 1):
        cmds.deleteUI('ColorChooser')

    cmds.window('ColorChooser', resizeToFitChildren = 1)
    cmds.columnLayout( adjustableColumn=True , cal = 'left')
    
    cmds.separator( h=10,style = 'none')
    cmds.text (label = "Select the color for your controls")
    cmds.separator( h=10,style = 'none')
    
    cmds.gridLayout(nr=1,nc =7, cwh = [30,20])
    red = cmds.iconTextButton('red_btn', bgc = (.9,0,0), vis = 1, c = 'red()')
    cmds.iconTextButton('orange_btn', bgc = (.9,.4,0),vis = 1, c= 'orange()')
    cmds.iconTextButton('yellow_btn', bgc = (.9,.9,0), vis = 1, c= 'yellow()')
    cmds.iconTextButton('green_btn', bgc = (0,.7,0), vis = 1, c = 'green()')
    cmds.iconTextButton('blue_button', bgc = (0,0,.9), vis = 1, c = 'blue()')
    cmds.iconTextButton('indigo_button', bgc = (.3,0,.5), vis = 1, c = 'indigo()')
    cmds.iconTextButton('violet_btn', bgc =(.8,0,.8), vis = 1, c= 'violet()')
    
    cmds.setParent( '..' )

    
    cmds.columnLayout( adjustableColumn=True , cal = 'right')
    cmds.button('Close', c = 'CloseColorChooser()')
    cmds.separator( h=10,style = 'none')
    cmds.separator( h=10,style = 'none')
    
    
    cmds.showWindow()
    
0 Likes
446 Views
1 Reply
Reply (1)
Message 2 of 2

Anonymous
Not applicable

At least two errors.
The first is that the button command should not be in quotes or parentheses so" 'red()' "should be " red ".
I have no idea what the second error is. but when I rewrite it from scratch with the above change the new one works so somewhere there is another error I just can't find.

I still have no idea why it works when I source the script in the editor and call it in the command line but it won't work as a module. But at least I have a new one that works as module now.

0 Likes