Search code examples
pythonslidermaya

keyword cant be an expression - sliders and selection menu


I'm trying to create code that will give the user the option on the primitive they'd like to create as well as the size of the object. Keyword cant be an expression is all I get but I can't find where it's referring to.

It was originally a syntax error inside of the cube object creation with a move command,I removed this and now its just this error

import maya.cmds as mt

def ShowUI():

    if mt.window("Main", exists = True):
        mt.deleteUI("Main")

    mt.window("Main", title = "Maya Primitives", w = 300, h = 500)
    mt.columnLayout("MainLayout", w = 300, h =500)
    mt.optionMenu("PolygonMenu", w = 250, label = "Polygon Selection:")
    mt.menuItem(label = "Sphere")
    mt.menuItem(label = "Cube")
    mt.menuItem(label = "Cylinder")
    mt.button("Create", label = "Create", w = 300, command=ObjectCreation)
    mt.button("Delete", label = "Delete", w = 300, command=DeleteButton)
    mt.button("Clear", label = "Clear", w = 300, command=SceneClear)
    mt.showWindow("Main")

def DeleteButton(*args):
    mt.delete()

def SceneClear(*args):
    mt.delete(all=True, c=True)


def ObjectCreation(*args):
    currentValue = mt.optionMenu("PolygonMenu", query=True, value=True)
    if currentValue == "Sphere":
        SphereRadius = mt.intSliderGrp(Sphradius, q = True, Value=True)
        finalSphere= mt.polySphere(r=SphereRadius, name = "Sphere", ch=False)


    elif currentValue == "Cube":
        CubeWidth = mt.intSliderGrp(CubeW, q = True, Value=True)
        CubeHeight = mt.intSliderGrp(CubeH, q = True, Value=True)
        CubeDepth = mt.intSliderGrp(CubeD, q = True, Value=True)
        finalSphere= mt.polyCube(w=CubeWidth, h=CubeHeight, d=CubeDepth, name = "Cube", ch=False)        


    elif currentValue == "Cylinder":
        CyclinderRadius =  mt.intSliderGrp(Cylradius, q = True, Value=True)
        CyclinderHeight =  mt.intSliderGrp(CylH, q = True, Value=True)
        finalCylinder= mt.polyCylinder(r=CylinderRadius, h=CylinderHeight, name = "Cylinder", ch=False)


def SphereSlider():
    Sphradius = mt.intSliderGrp(1="Radius",min=0,max=25, field=True)

def CubeSlider():
    CubeW = mt.intSliderGrp(1="Width", min=0, max=25, field=True)
    CubeH = mt.intSliderGrp(1="Height", min=0, max=25, field=True)
    CubeD = mt.intSliderGrp(1="Depth", min=0, max=25, field=True)

def CylinderSlider():
    Cylradius = mt.intSliderGrp(1="Radius",min=0,max=25, field=True)
    CylH = mt.intSliderGrp(1="Height", min=0, max=25, field=True)


ShowUI()

Solution

  • It helps a lot if you post the exact error message with stack trace. In this case it says that the error occurs in line 46 in this line:

    Sphradius = mt.intSliderGrp(1="Radius",min=0,max=25, field=True)

    And it means that you use 1="Radius" is not correct because 1 is no a keyword. I suppose you wanted to call it label="Radius".