5 Tips and scripts for working with cameras effectively in Maya

When you tend to do the same repetetive tasks multiple times a day, creating a scripting solution that shaves even a second off of your task can add up quickly over time, let alone help to curb the mental insanity that is working with 3D.  So here are a few scripts I use every day to speed up my workflows when dealing with cameras, which is constantly.


Tip 1 - Consistent naming

In order to implement a scalable and flexible camera scripting workflow you need to have consistent namings for cameras.  I use renderCam for any camera that will be the main camera to render to. Here is a script that will automatically create a camera named accordingly - 

string $createRenderCam[] = `camera`;
string $selectCam[] = `select $createRenderCam`;
rename $selectCam renderCam;

You can name your cameras whatever you like, but it is important to keep them consistent otherwise some scripts will not work.  Also if you decide to name your cameras something differently, you have to reflect that naming convention in the scripts listed here.


Tip 2 - Toggle through all active perspective cameras

This super useful tip was found on this thread-

This is a script to toggle between all active perspective cameras.  This saves a lot of time as the alternative methods for switching between cameras are - 

Panels > perspective > renderCam
Drag the camera from the outliner into the perspective viewport
Hold spacebar (to bring up hotbox) > right click marking menu (over the center maya text) > renderCam

Each one is annoying in its own right, hotbox is the fastest but with large scenes you can get considerable lag when bringing up the hotbox so this solution is much faster

I have this assigned to a hotkey - SHIFT + C

//Switch Perspective Cameras
$currentCamera = `lookThru -q`;
string $allCameras[];
$allCameras = `listCameras -p`; // This will select perspective cameras only
int $nextCamera;
if($currentCamera == $allCameras[$pos]) $nextCamera = $pos+1;
if($nextCamera>=size($allCameras)) $nextCamera = 0;
lookThru $allCameras[$nextCamera];

Note: this will not work by default with orthographic cameras without modifying the code slightly


Tip 3 - Render from renderCam

This is a script that will automatically render from renderCam, without having to go to the render view >  render > renderCam, as often if you just hit render it will default to the perspective camera.  

This script is also useful as you do not have to switch to the renderCam to render, you can render the correct camera from any active camera. 

I have this assigned to SHIFT + Q, which is the standard 3ds Max hotkey for rendering

setFocus "MayaWindow";
renderWindowRenderCamera render renderView renderCam;


Tip 4 - Render from active camera

Similar to the previous render from renderCam script, except this will render from the current active camera, regardless of if it is the default perspective camera or a custom camera. This is useful if you have multiple shot cameras in your scene, or multiple cameras in general, and still would like a hotkey to render.

I have this hotkey assigned to CNTRL + SHIFT + Q

setFocus "MayaWindow";
$currentCamera = `lookThru -q`;
renderWindowRenderCamera render renderView $currentCamera;

Note: For both this script and the previous script, it will automatically set focus on the maya viewport which will enable you to call the render command.  However sometimes this does not behave correctly and you will need to actually click on an active modeling window in order for it to work; for instance if you are working in the vray frame buffer, comparing images etc, you will need to click on the active viewport to make it work.


Tip 5 - Pre/Post render script to enable/disable image plane

I would say about 95% of the time when working with image planes you do not want them to render along with your final render.  Rather than having to remember to go to the image plane and change its visibility to none, you can use pre and post render MEL to disable the image plane at render time, and then re-enable it once the render finishes.

Copy this code into the MEL/Python callbacks section of the render globals, under the Common tab

// Disable image plane, Place this in Pre Render MEL
         $imagePlaneList = `ls -type imagePlane`;
         for ($visImPlanes in $imagePlaneList)
         setAttr ($visImPlanes + ".displayMode") 0;

// Enable image plane, Place this in Post Render MEL
         $imagePlaneList = `ls -type imagePlane`;
        for ($hidImPlanes in $imagePlaneList)
        setAttr ($hidImPlanes + ".displayMode") 3;