Scripting,  Maya

Create a Camera and Autosetup for Rendering

Create a Camera and Autosetup for Rendering

When rendering with Mental Ray I always use a dedicated RenderCam. To create this camera I usually do the following

  1. Create the Camera
  2. Rename the Camera to “RENDER_CAM”
  3. Add the Lens shader “mia_exposure_photographic”
  4. Look through the Camera, Position it
  5. Do Test Renders

What really bothered me about this process, is that these steps are always the same and for Animations, I forgot to set this camera as the RenderCam for Batch Render. I created this short script to do these steps automatically:

import pymel.core as pm

def createRenderCam(name = "RENDER_CAM", exposure = True):
    '''
    Creates a camera and renames it

    str name: name of the camera
    bool exposure: connect a mia\_exposure\_photographic node to the camera
    '''
    if not pm.objExists(name):
        cam = pm.camera()\[0\]
        pm.rename(cam, name)
        \[cam.renderable.set(cam.name().startswith(name)) for cam in pm.ls(cameras=True)\]
    cam = pm.PyNode(name)

    if exposure:
        if not cam.miLensShader.isConnected():
            node = pm.createNode("mia\_exposure\_photographic")
            node.film_iso.set(800)
            node.f_number.set(1.2)
            node.gamma.set(1)
            pm.connectAttr(node.message, cam.miLensShader, force=True)

    cam.getShape().setDisplayResolution(True)
    pm.lookThru(name)

    pm.select(cam)