I'm creating a user interface in Maya using Python. I keep getting this error:
Error: line 1: keyword can't be an expression
Does anybody know how to counter this?
import maya.cmds as cmds
if mc.window(ram, exists =True):
mc.deleteUI(ram)
ram = cmds.window("RenamerWin",t = "Renamer Tool", w=300, h=300)
cmds.columnLayout(adj = True)
cmds.text("Welcome to the tool renamer")
cmds.separator(h=10)
cubW = cmds.intSliderGrp(1 = "Width",min =0, max =10, field =True)
cubH = cmds.intSliderGrp(1 = "Height",min =0, max =10, field =True)
cubD = cmds.intSliderGrp(1 = "Depth",min =0, max =10, field =True)
cmds.button(l = "Create a Cube",c="myCube()")
cmds.showWindow(ram)
def myCube():
myCubeWidth = cmds.intSliderGrp(cubW , q= True,value =True)
myCubeHeight = cmds.intSliderGrp(cubH , q= True,value =True)
myCubeDepth = cmds.intSliderGrp(cubWD , q= True,value =True)
finalCube = cmds.polyCube(w=myCubeWidth,h=myCubeHeight,d=myCubeDepth , n = "myCube")
Couple of things:
mc
and cmds
interchangeably. This might work if you'd done both at different times in your listener but it won't work as writtenram
is not defined in before you use it. Line 2 will fail for anybody who hasn't run this before.myCube()
Here's a working version; check the differences with what you had. Note that I put the whole thing inside a def to make sure it doesn't get you in trouble with the leftovers of earlier runs:
import maya.cmds as cmds
def example ():
ram = 'RenamerWin'
if cmds.window(ram, q = True, exists =True):
cmds.deleteUI(ram)
ram = cmds.window("RenamerWin",t = "Renamer Tool", w=300, h=300)
cmds.columnLayout(adj = True)
cmds.text("Welcome to the tool renamer")
cmds.separator(h=10)
cubW = cmds.intSliderGrp(l = "Width", min =0, max = 10, field = True)
cubH = cmds.intSliderGrp(l = "Height", min =0, max = 10, field = True)
cubD = cmds.intSliderGrp(l = "Depth", min =0, max = 10, field = True)
def myCube(_):
myCubeWidth = cmds.intSliderGrp(cubW , q= True,value =True)
myCubeHeight = cmds.intSliderGrp(cubH , q= True,value =True)
myCubeDepth = cmds.intSliderGrp(cubD , q= True,value =True)
finalCube = cmds.polyCube(w=myCubeWidth,h=myCubeHeight,d=myCubeDepth , n = "myCube")
cmds.button(l = "Create a Cube",c=myCube)
cmds.showWindow(ram)
example()