Maya 语法错误
Syntax error in Maya
我通常不会 post 一些看起来很基本的东西,但我整个下午都在困惑这个问题。
每当我尝试 运行 这段代码时,Maya 都会给我一个非常不具体的 'Syntax error',有人能看到问题吗?
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)
更改此行,(漏了一个,
)
(btn4, "top" 144)
至
(btn4, "top", 144)
正如 itzmeontv 所述,您在第 40 行漏掉了一个逗号。
(btn4, "top", 144)
我还想提一下,当我编码时,我通常会在 Maya 的脚本编辑器历史记录菜单下打开 "Line numbers in errors" 和 "Show Stack Trace"。
如果没有打开“显示堆栈跟踪”或“错误中的行号”,您将只会看到这样一条模糊的错误消息:
# 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 #
您甚至会得到一个 ^ 符号,告诉您在包含错误的代码行中发生错误的位置。
我希望这可以帮助您更有效地查找错误!
我通常不会 post 一些看起来很基本的东西,但我整个下午都在困惑这个问题。 每当我尝试 运行 这段代码时,Maya 都会给我一个非常不具体的 'Syntax error',有人能看到问题吗?
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)
更改此行,(漏了一个,
)
(btn4, "top" 144)
至
(btn4, "top", 144)
正如 itzmeontv 所述,您在第 40 行漏掉了一个逗号。
(btn4, "top", 144)
我还想提一下,当我编码时,我通常会在 Maya 的脚本编辑器历史记录菜单下打开 "Line numbers in errors" 和 "Show Stack Trace"。
如果没有打开“显示堆栈跟踪”或“错误中的行号”,您将只会看到这样一条模糊的错误消息:
# 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 #
您甚至会得到一个 ^ 符号,告诉您在包含错误的代码行中发生错误的位置。
我希望这可以帮助您更有效地查找错误!