문제

I'm having troubles starting maya from a python script with a mel command. Or rather I have a problem getting the mel command to run, maya launches just fine.

This is what the maya documentation says about starting with a mel command:

-command [mel command]

Runs the specified command on startup. The command should be enclosed in double quotes to protect any special characters, including spaces.

Whatever I try Maya just ignores my doublequotes and gives me a syntax error. This is my code:

import os
dir = "D:\exampleProject\maya"
os.system('maya.exe -command \"setProject \"'+dir+'\"\"')

I figure this would be read as this in maya: setProject "D:\exampleProject\maya" (which is what I want) What I get is instead: setProject D:\exampleProject\maya which generates a syntax error in maya due to the lack of "" around the directory path.

도움이 되었습니까?

해결책

Answer from comments

From the MEL documentation, it states that "Every statement in MEL must end with a semi-colon (;)."

MEL strings also require quotations to be escaped, therefore double escape the internal quotations.

'maya.exe -command \"setProject \\\"'+dir+'\\\";\"'

다른 팁

If all you need is to set the project you can use the startup flag "-proj"

maya.exe the/scene/iwant/to/open.ma -proj the/project/root

See the Documentation

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top