五月语法错误

2024-09-28 20:42:46 发布

您现在位置:Python中文网/ 问答频道 /正文

我通常不会发一些看起来很基本的东西,但我整个下午都在为这个感到困惑。 每当我尝试运行这段代码时,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)


Tags: thetruetranstopbuttonleftlabelcommand
2条回答

更改此行,(缺少一个,

(btn4, "top" 144)

^{pr2}$

正如itzmeontv提到的,您在第40行遗漏了一个逗号。在

(btn4,“顶部”,144)

我还想指出,在编写代码时,我通常会在Maya的“脚本编辑器历史”(Script Editor History)菜单下启用“错误行号”(Line numbers in errors)和“显示堆栈跟踪”(Show Stack Trace)。在

如果不启用“显示堆栈跟踪”或“错误中的行号”,则只会看到如下模糊的错误消息:

# Error: SyntaxError: invalid syntax #

启用错误行号时,将在脚本编辑器中看到以下输出:

# Error: line 1: invalid syntax #

请注意,报告遇到错误的第1行没有正确反映代码中实际错误的位置。在

最后,当启用Show Stack Traceerrors中的行号时,您将在脚本编辑器的输出中看到更详细和详细的错误消息:

# 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 # 

您甚至可以在包含错误的代码行中得到一个^符号,指示错误发生的位置。在

我希望这能帮助你更有效地捕杀虫子!在

相关问题 更多 >