Maya Python error: keyword can't be an expression?

Maya Python error: keyword can't be an expression?

我正在使用 Python 在 Maya 中创建用户界面。我不断收到此错误:

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

有人知道如何应对吗?

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. 您正在交替使用 mccmds。如果您在不同的时间在您的侦听器中完成这两个操作,这可能会起作用,但它不会像写的那样起作用
  2. ram 在您使用之前未定义。对于之前没有 运行 的任何人,第 2 行都会失败。
  3. 您输入的是数字 1,但您想要字母 L。
  4. 您输错了 myCube()
  5. 中最后一个滑块的名称
  6. 按钮命令需要带参数。

这是一个工作版本;检查与您所拥有的差异。请注意,我将整个内容都放在 def 中,以确保它不会让您遇到早期 运行s:

的剩余问题
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()