我通常不会发布看似基本的东西,但整个下午我一直在困惑。 每当我尝试运行此代码时,Maya都会给我一个奇妙的非特定“语法错误”,有人能看到这个问题吗?
import maya.cmds as cmds
def listSelMesh(*args):
cmds.textScrollList("ab_meshList", en=1, ra=1) #CLEAR THE OLD LIST
trans = cmds.ls(sl=1) #LIST SELECTED OBJECTS
meshList = cmds.listRelatives(trans, c=1) or [] #GET ANY SHAPES
shapeList = cmds.ls(meshList, t=1) #GET ANY MESHES
for trans in shapeList:
cmds.textScrollList("ab_meshList", e=1, a=trans) #APPEND THE CLEARED LIST WITH THE NEW SHAPES
#Create the UI
def createUI(pWindowTitle, pApplyCallback):
windowID = 'ba_skinExport'
#If the UI is already open, delete the pre-existing instance
if cmds.window(windowID, exists=True):
cmds.deleteUI(windowID)
cmds.window(windowID, title=pWindowTitle, sizeable=True, resizeToFitChildren=True)
#Layout the columns in the UI
cmds.columnLayout(adjustableColumn=True)
form = cmds.formLayout()
text1 = cmds.text(label='Selected mesh')
shapeList = cmds.textScrollList("ab_meshList", p=form, h=75)
btn1 = cmds.button(label='Load', command=listSelMesh)
btn2 = cmds.button(label='Export', command=pApplyCallback)
btn3 = cmds.button(label='Import', command=pApplyCallback)
btn4 = cmds.button(label='Cancel', command=cancelCallback, w=85)
cmds.showWindow()
cmds.formLayout(form, e=1,
attachForm=((shapeList, "top", 10), (shapeList, "left", 100), (shapeList, "right", 10),
(btn1, "top", 92), (btn1, "left", 100), (btn1, "right", 10),
(text1, "top", 92), (text1, "left", 20),
(btn2, "top", 144), (btn2, "left", 100), (btn2, "right", 100),
(btn3, "top", 144), (btn3, "left", 100), (btn3, "right", 100),
(btn4, "top" 144), (btn4, "left", 10)
))
createUI('ba_skinExport', applyCallback)
答案 0 :(得分:3)
更改此行,(错过了,
)
(btn4, "top" 144)
到
(btn4, "top", 144)
答案 1 :(得分:1)
正如itzmeontv所说,你错过了第40行的逗号。
(btn4,“top”,144)
我还想提一下,当我编码时,我通常会在Maya的“脚本编辑器历史记录”菜单下打开“错误中的行号”和“显示堆栈跟踪”。
如果没有显示错误中的显示堆栈跟踪或行号,您将只会看到一个模糊的错误消息,如下所示:
# Error: SyntaxError: invalid syntax #
在错误中启用行号时,您将在脚本编辑器中看到此输出:
# Error: line 1: invalid syntax #
请注意,报告遇到错误的第1行无法正确反映代码中的实际错误。
最后,当启用显示堆栈跟踪和错误中的行号时,您将在脚本编辑器的输出中看到更详细和详细的错误消息:
# Error: invalid syntax
# File "<maya console>", line 40
# Error: invalid syntax
# File "<maya console>", line 40
# (btn4, "top" 144), (btn4, "left", 10)
# ^ ^
# SyntaxError: invalid syntax #
你甚至会得到一个^符号,显示包含错误的代码行发生错误的位置。
我希望这可以帮助你更有效地追捕错误!