从 Python 调用 MEL 脚本 - 执行 MEL 脚本时出错
Call MEL script from Python - Error occurred during execution of MEL script
我正在尝试创建一个简单的 Python 脚本,该脚本将从 Maya 中调用 MEL 脚本来创建立方体。耶!应该是相当直截了当的,尽管我可能把源文件的语法弄错了。
这是我的:
runMEL.py Python 文件:
将 maya.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
global proc myMELScript()
// call a MEL script with Python
{
polyCube -w 1 -h 1 -d 1 -sx 1 -sy 1 -sz 1 -ax 0 1 0 -cuv 4 -ch 1;
print("MEL just made a cube!");
}
我从控制台得到以下信息:
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 #
你几乎做对了,你必须将路径作为字符串传递并转义它。此外,mel 对正斜杠 /
和反斜杠 \
很挑剔,它期望 /
应该这样做:
mel.eval('source "D:/Maya_Python/myMELScript.mel"')
注意:通常在python中你可以写你的路径以及
D:\Maya_Python\myMELScript.mel
但是 mel 不够聪明所以它会转义转义符号 :D
我正在尝试创建一个简单的 Python 脚本,该脚本将从 Maya 中调用 MEL 脚本来创建立方体。耶!应该是相当直截了当的,尽管我可能把源文件的语法弄错了。
这是我的:
runMEL.py Python 文件: 将 maya.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
global proc myMELScript()
// call a MEL script with Python
{
polyCube -w 1 -h 1 -d 1 -sx 1 -sy 1 -sz 1 -ax 0 1 0 -cuv 4 -ch 1;
print("MEL just made a cube!");
}
我从控制台得到以下信息:
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 #
你几乎做对了,你必须将路径作为字符串传递并转义它。此外,mel 对正斜杠 /
和反斜杠 \
很挑剔,它期望 /
应该这样做:
mel.eval('source "D:/Maya_Python/myMELScript.mel"')
注意:通常在python中你可以写你的路径以及
D:\Maya_Python\myMELScript.mel
但是 mel 不够聪明所以它会转义转义符号 :D