Maya Python错误:关键字不能成为表达式?

时间:2017-03-09 19:37:53

标签: python user-interface maya

我正在使用Python在Maya中创建用户界面。我一直收到这个错误:

Error: line 1: keyword can't be an expression

有人知道如何解决这个问题吗?

image

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")

1 个答案:

答案 0 :(得分:0)

一些事情:

  1. 您可以互换使用mccmds。如果您在听众中的不同时间完成了这项工作,但它不会按照书面形式工作,那么这可能会有效。
  2. 在您使用之前未定义
  3. ram。对于之前没有运行过此操作的人来说,第2行将会失败。
  4. 当您想要字母L时输入数字1。
  5. 您错误输入了myCube()
  6. 中最后一个滑块的名称
  7. 按钮命令需要参数。
  8. 这是一个工作版本;检查你所拥有的差异。请注意,我将整个内容放在def中,以确保它不会让您遇到早期运行剩余时间的麻烦:

    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()