Message 1 of 2
script flow question
Not applicable
04-20-2021
09:03 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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()