Question

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.

Was it helpful?

Solution

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+'\\\";\"'

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top