Friday, April 4, 2014

Setting the correct Pixel Aspect in Maya

0 comments
I just recently ran into the issue of setting the pixelAspectRatio of the defaultResolution to a value that wasn't what maya was setting based on the width and height. I couldn't really find any answers on the net so I figure i'd put my answer up.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import maya.cmds as cmds


def setResolution(width=1920, height=1080, pixelAspect=1.0):
    '''
    Sets render resolution properly.

    @param width- The width of the resolution.
    @param height- The width of the resolution.
    @param pixelAspect- The pixel aspect to set the defaultResolution to.

    Returns None
    '''
    #Calculates the device aspect since pixel aspect isn't an actual attribute.
    device_aspect = float(width * pixelAspect)/float(height)

    #Set the Lock Device Aspect Ratio. IMPORTANT!
    #If you don't do this it won't work.
    cmds.setAttr("defaultResolution.lockDeviceAspectRatio", 1)

    #Set width, height, and aspect ratio.
    cmds.setAttr("defaultResolution.width", width)
    cmds.setAttr("defaultResolution.height", height)
    cmds.setAttr("defaultResolution.deviceAspectRatio", device_aspect)

if __name__ == "__main__":
    setResolution(width=3168, height=2376, pixelAspect=2.0)

Hope this saves someone the time it took me to figure this out!

-Chris