Maya has three methods of interacting with it without a GUI. The first is by sending it commands via Unix standard output and a commandPrompt port (covered here), the second is in prompt mode where it basically runs in a terminal as a MEL or Python interpreter, letting you open scenes and process them with text commands. The other method is to ask it to do commands while opening a scene for rendering, and this sounds like a hack but it’s actually really powerful because it can be shell scripted and used with variables like multiple selected files. It also assumes you’re working with the file you’ve specified to render, so you don’t have to explicitly open it like when using the -prompt mode interpreter. I’ve been playing with UDK in Parallels Desktop 7 (works great) and I have all these stock tree models in Maya format that I’d like in FBX for UDK. Since FBXConverter can’t handle Maya files, the only GUI alternative is to open these one by one and export FBX files. Very tedious. So what I’ve done is used the render command with a -preRender “FBXExport -f /path/to/file.fbx” argument and just made the render a hardware render and written to /tmp so it doesn’t take any render time and it will be deleted by the OS later.
For the commands, the headless interpreter mode works by launching Maya with “-prompt” at the end of the launch command in a terminal window:
That’s on OS X and same in Linux with different bath to the maya binary. In Windows it’s done with a launch flag on the application, I think. The render command works like this:
/Applications/Autodesk/maya2012/Maya.app/Contents/MacOS/Render -r hw -s 1 -e 1 -rd /tmp/ -preRender “putYourCodeHere” /path/to/file.mb
On Windows, you’ll need to use a different temp path. Here’s an example of the two latter methods doing the same action.
The drawback to the renderer method is that it’s not really meant for multi-line operations (merge, then export, for example) so it’s best used for simple exporting. If you want to do multiline processing as a batch, take a look at piping stdout to Maya. But for the simple export of FBX files, it’s great and I whipped up a shell script and Automator action to work with multiple files:
You can grab the shell script here and the Automator action here. Both the Automator action and the shell script accept multiple files as input and will save the FBX files to the same folder as the source file. Sorry, Windows users - it uses bash so there’s no way to get this to run on a Windows machine without Cygwin and I’m not sure that would work either.