Maya list of image formats for render globals

When setting the image format for rendering through code you have to do something like this:

from maya import cmds
# set to jpg
cmds.setAttr("defaultRenderGlobals.imageFormat", 8)

8 happens to be “jpg”
but how do you know (reliably) what the other 63 options are?
(There are 64 in my installation of Maya 2018)

Here’s how to get the default formats that ship with Maya.

TL;DR

from maya.app.general.createImageFormats import ImageFormats
from pprint import pprint
# 'extension' is the string format. 'ident' is the int value for the enum
formatMapping = {imageDescriptor.extension: imageDescriptor.ident for imageDescriptor in ImageFormats().formats}
pprint(formatMapping)

It took me a bit of searching through the WEBious alleyways of CG forums until I found this post:
https://forums.cgsociety.org/t/saving-rendered-image-from-a-python-script-in-maya/1801930

That lead me to the answer, hopefully this saves someone some time.

This is pretty handy for UIs or doing some kind of sanity checking on rendering tools.

A bit more technical info if you want to keep reading

Run this if you want to see the python module itself.

from maya.app.general import createImageFormats
print createImageFormats.__file__

The code below will give you a list of ImageDescriptor objects that contain a bunch of information about the available image type, including the extension, integer identifier, description, etc.

createImageFormats.ImageFormats().formats

Cheers,
F

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Blog at WordPress.com.

Up ↑

%d bloggers like this: