从Python调用MEL脚本在执行MEL脚本期间发生错误

2024-10-01 11:25:13 发布

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

我正在尝试创建一个简单的Python脚本,它将从Maya中调用MEL脚本来创建立方体。耶!应该是相当直截了当,虽然我可能得到了源文件的语法错误。在

以下是我所拥有的:

在runMEL.pyPython文件: 进口玛雅.mel作为mel

def runMEL():
  print ("Running MEL from Python!")
  mel.eval('"source D:\Maya_Python\myMELScript.mel;"') # source of the file
  mel.eval("myMELScript;") #name of the function

runMEL() # call the function above

以及MEL脚本myMELScript.mel在

^{pr2}$

我从控制台得到以下信息:

Running MEL from Python!
// Error: "source D:\Maya_Python\myMELScript.mel;"; // 
// Error: Line 1.40: Syntax error // 
# Error: RuntimeError: file <maya console> line 5: Error occurred during execution of MEL script
Line 1.40: Syntax error #

Tags: ofthefrom脚本sourceevalfunctionerror
1条回答
网友
1楼 · 发布于 2024-10-01 11:25:13

你差一点就搞定了,你必须把路径作为一个字符串传递,然后逃出它。此外,mel对前斜杠/和后斜杠\很挑剔,它期望/

应该这样做:

mel.eval('source "D:/Maya_Python/myMELScript.mel"')

注意:通常在python中,您可以编写路径以及

^{pr2}$

但是梅尔不够聪明,所以它会逃过逃跑的标志:D

相关问题 更多 >