Scripting the output file format for viewport captures


Here’s how to set the default value for the FormatType list in the Capture Viewport dialog box.

from siutils import si		# Application
from siutils import log		# LogMessage
from siutils import disp	# win32com.client.Dispatch
from siutils import C		# win32com.client.constants

# Set the capture options
oViewportCapture = si.Dictionary.GetObject("ViewportCapture")
paramFormatType = si.Dictionary.GetObject( "ViewportCapture.FormatType" )

# Set default to JPEG
paramFormatType.Value = 5

# Display Viewport Capture dialog
si.CaptureViewport( 2, True )


# FormatType values
# -----------------
# 0 Alias
# 1 AVI
# 2 BMP
# 3 Cineon (DPX)
# 4 Cineon (FIDO)
# 5 JPEG
# 6 Memory mapped
# 7 mental ray color
# 8 OpenEXR
# 9 PGM
# 10 Photoshop PSD
# 11 Pict
# 12 PNG
# 13 PPM
# 14 Quicktime
# 15 SGI
# 16 Softimage .pic
# 17 Son Playstation2 TIM2/CLUT2
# 18 Targa
# 19 Tiff
# 20 Valve
# 21 Wavefront
# 22 YUV

If you are scripting a non-interactive viewport capture, you don’t use FormatType. Instead, the output file format is determined by the file extension of the output file name.
Here’s a Python version of the example on the CaptureViewport reference page.

from siutils import si		# Application
from siutils import log		# LogMessage
from siutils import disp	# win32com.client.Dispatch
from siutils import C		# win32com.client.constants
import win32com.client.dynamic

# Get the current frame
fc = si.ActiveProject.Properties("Play Control").Parameters("Current").Value

# Set the capture options
oViewportCapture = si.Dictionary.GetObject("ViewportCapture")

# Capture a 1-frame sequence 
start = oViewportCapture.NestedObjects("Start Frame")
win32com.client.dynamic.Dispatch(start).Value = fc

end = oViewportCapture.NestedObjects("End Frame")       
win32com.client.dynamic.Dispatch(end).Value = fc

# Specify the output file name
# For scripted captures, the output file format is determined by the extension
name = oViewportCapture.NestedObjects("File Name")
win32com.client.dynamic.Dispatch(name).Value = "C:\\test.jpg"

# No dialog
si.CaptureViewport( 2, False );

6 thoughts on “Scripting the output file format for viewport captures

  1. Pardon my ignorance Stephen, but why cant one do stuff like this:
    oViewportCapture = si.Dictionary.GetObject(“ViewportCapture”)
    oViewportCapture.Start = ##

    and instead must go with the NestedObjects method?
    it seems to be the only way it works, but it looks inconsistent with everything else

    • Hi Gustavo

      The ViewportCapture object isn’t an X3DObject and it doesn’t expose its parameters through the object model. If you look in the SDK Explorer, you’ll see that ViewportCapture is a CollectionItemLegacy object that doesn’t support the Parameters property (ViewportCapture used to be an SIObject, which again, did not support the Parameters property).

      You could skip the NestedObjects step and use Dictionary.GetObject to get the parameters.

      And ViewportCapture was always scriptable with GetValue and SetValue.

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