For one of my more recent videos, I decided to render using the command line renderer. This allowed me to set up a batch render that rendered the same scene from different camera angles during different time ranges and allowed me to easily save the output images in separate folders. I could even set up a shell script to render multiple sets of images in one batch and I could even have the script send me an SMS text message or email when certain sets of jobs complete.
The easiest way to get rendering via command line is to navigate to the maya2012 folder in your Applications directory. If you double click on Maya Terminal.term, Terminal will open and execute a small script to set up the Maya specific commands. If you want to just render a file without customizing any options you can type
So if I wanted to render my scene called testScene.ma that was located in ~/maya/ with mental ray I would enterIf you're not familiar with using file names in Terminal, a quick way is to type
Then drag and drop the file into the Terminal window and the pathname will be added for you.
Alias maya to Maya Terminal.term Commands
If you read the documentation for the command line renderer it recommends you run the Maya Terminal.term to launch a new shell with the correct settings to use the Maya specific shell commands. If you do that you will notice that doing this just launches an instance of Terminal.app and runs a shell script to set up the correct environment variables. To make things run a little smoother, I used the .bash_profile alias maya to execute that shell script. You can accomplish this by starting a new shell, and editing your .bash_profile file located in your home directory with Vim, Nano or some other text editor. For example, I added the line
So now I can start a new shell, type maya, and everything is set up for rendering.
More Advanced Commands
By default the command line renderer will use the Render Settings from your scene file to render, but the power of command line rendering is that you can easily override Render Settings quickly. If you type
(after initializing the maya command), a list of render flags will be printed out. The most interesting are render directory, camera, render layer, start frame and end frame. Through combinations of these, you can have one 'master' scene set up with default render options, and then render out different combinations of layers, time ranges, cameras and send them all to different directories on your computer. Here is an example of a common render command I use
This will render the masterlayer render layer from the main_cam camera in the scene.ma file. It will render frames 770-950 and place them in the specified directory.
Setting Up a Shell Script for Batch Rendering
To create a batch file you can open up a blank text file and put one render command per line. If you save the file with the format .sh, you can then run the file through Terminal. The format might be as follows:
Note: You can use the more advanced Render commands above as well. Then to run the batch command, you can open up a new shell, type maya then type
Text Message Alert
As an addition to the shell script above, you can use the built in mail command to send yourself an email or SMS message when the renders have completed. You can insert the command after each phase of rendering is completed, or just at the end so you know when your computer is available for use again.
Whatever you put in the echo command will be piped into the mail command with the subject specified by the -s argument to the specified email address. Most mobile carriers support sending text messages via email and you can simply Google your carrier to find out the format of the address to send it to. For example, to send an SMS message to AT&T phones in the U.S. you can use the format, <10-digit wireless phone number>@txt.att.net
Why Render from the Command Line?
- The biggest reason is memory consumption. When rendering from Maya directly, you need to have your scene file open and then when you render it starts another process that actually performs the render. If you don't have Maya open you have more available memory to use for the render.
- Easier to customize. You can choose to render certain layers with certain frame ranges and store the results in different directories. There are also advanced options to set up Mel scripts to be executed before and after each rendering job.
- Ability to batch render more easily.
- Can easily set up multiple render jobs from one scene file.
When I render on the Mac via the command line, I noticed that my computer fell asleep after the allotted time and the renders were put on hold. To overcome this I downloaded the free app Caffeine.