我在使用 mel 命令从 python 脚本启动 Maya 时遇到问题。或者更确切地说,我在运行 mel 命令时遇到问题,maya 启动得很好。
这是 Maya 文档中关于使用 mel 命令启动的内容:
-command [mel command]
Runs the specified command on startup. The command should be enclosed in double quotes to protect any special characters, including spaces.
无论我尝试什么,Maya 都会忽略我的双引号并给我一个语法错误。 这是我的代码:
import os
dir = "D:\exampleProject\maya"
os.system('maya.exe -command \"setProject \"'+dir+'\"\"')
我想这在maya中会被读成这样:setProject“D:\exampleProject\maya”(这就是我想要的) 我得到的是:setProject D:\exampleProject\maya,由于目录路径周围缺少“”,它会在 Maya 中生成语法错误。
最佳答案
评论中的回答
MEL 文档中指出 "Every statement in MEL must end with a semi-colon (;)."
MEL strings also require quotations to be escaped ,因此对内部引号进行双重转义。
'maya.exe -command \"setProject \\\"'+dir+'\\\";\"'
关于python - Maya 忽略我的双引号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19320107/