Introduction?
I wasn't able to find much information about running scripts within mayabatch when I first started looking into how to do this myself. There's loads of info out there about running renders via mayabatch but not much about how to do other things with it (ie run scripts on a file rather than just rendering a file).I hope to lay out some basic tutorials over the next few month on how to do this, as much for myself as anything else. For anyone else reading this please note the following:
This will only be relevant to Windows and possibly with specific reference to Windows 10. Sorry to Mac and Linux users out there but I've not got experience of using those systems so I have nothing to offer about how to do this on those OS.
These tutorials will also assume at least a basic understanding of Python.?If you're not familiar with Python, then I would recommend checking out Jeremy Ernst's Vimeo channel, specifically his Building Maya Interfaces with Python series which starts with this video: https://vimeo.com/42848594
First I should start with how to actually run mayabatch.exe via the command line in windows, a very basic step but one that seems to be overlooked by others when teaching about this kind of thing.
Part 1 - Running mayabatch for the first time
There are two basic ways to get mayabatch up and running.- Run cmd directly in the Maya bin
- Define where the mayabatch.exe actually is on the system before you try and run it.
Option #1 - Run cmd in the Maya bin
- Navigate to your maya bin folder. This is the program files of your windows machine. Most likely it will look like this:
C:\Program Files\Autodesk\Maya2015\bin?
(obviously change the maya version to the one you're using eg 'Maya2016')
- Type cmd into the address bar of the explorer once you're here:
This is where you want to type 'cmd'
- This will open a cmd terminal looking like this:
This means that the cmd terminal will understand what and where mayabatch is. Note that this is different from running cmd from anywhere else in Windows. (ie from the start menu, the Run command, or the same process but in another folder)
- type in mayabatch.exe and hit enter, this will open a version of maya without a UI.?
It'll take a second or two to start but and once it's loaded it it'll close itself down again given that it's got nothing to do. You'll basically see something like this:
I'm not really sure what the error about Bifrost is about, something for me to look into another time perhaps.
Option #2 - Define where mayabatch is on the system
- Open a normal command prompt terminal. Type 'cmd' into the start menu and hit enter.
- This will bring up a command terminal much like the other but notice that the folder path is different. It should default to the current user's path.
- This time we need to specify where the mayabatch.exe actually is for it to run. Type in the file path for mayabatch (or copy and paste it). This will most likely be:?
C:\Program Files\Autodesk\Maya2015\bin\mayabatch.exe
(again change the version number to the version of maya you have installed)
Here's the error you get when you try to run mayabatch with a space in program files
- ?The thing is this will cause errors in the command prompt because it can't resolve the space in 'Program Files' part of the path. The way around this is to change the path we're using slightly. Changing 'Program Files' to 'Progra~1' allows command prompt to read the path properly.
C:\Progra~1\Autodesk\Maya2015\bin\mayabatch.exe
Here we see mayabatch running. Note that where you put the '~1' is important as if it's in the wrong place you'll get an error.