Playblast completeFilename flag in 2012…

I’ve been working on updating our animation library tool at work for use in Maya 2012 and noticed an issue with properly generating thumbnails. After scouring the internet for awhile, I found out I wasn’t the only one experiencing an issue with the playblast command. When using the completeFilename flag (to save an image without zero-padding), the image won’t save, and Maya raises no warnings or errors about it.
Fortunately, I came across a post from Nathan Horne, showing how to generate thumbnails using the Maya API commands. I added some additional checks to the original snippet:

def writeThumbnailFromView(filename, compression, modelPanel=None):
    #Import api modules
    import maya.OpenMaya as api
    import maya.OpenMayaUI as apiUI

    #Grab the last active 3d viewport
    view = None
    if modelPanel is None:
        view = apiUI.M3dView.active3dView()
    else:
        view = apiUI.M3dView()
        apiUI.M3dView.getM3dViewFromModelEditor(modelPanel, view)

    #read the color buffer from the view, and save the MImage to disk
    image = api.MImage()
    view.readColorBuffer(image, True)
    image.writeToFile(filename, compression)

So far it seems more efficient for my needs than the playblast command, as my tool is now able to avoid capturing the wrong viewport, and I can control the image without messing with render settings.


3 comments

  1. Hi , thats a cool pieace of code, but…..
    what would happen if i wanted to make sure the capture width and height were as the render globals.
    the main disadvantage i find in this method is that every capture is different then the other according to your UI layout sizes and the active screen size…
    can u capture with api and maintain a snapshot of a certain size??

    • I use this function to capture from modelViews within my own UIs. These modelViews are coded with a fixed size so I never addressed the issue you mentioned.

      Off the top of my head, if you wanted to capture a fixed size from one of the normal viewPorts, I would look into making a temporary modelView in a separate window that’s resized to match the render globals.

      • thanks for the quick reply,
        yes, it occurred to my after writing the question here that i can just create my own panel, i tested it out and of course it works nicely, but flickers for the panel creation in a not as elegant manner as before.
        i think that when already using such an elegant approach (background api) i thought there might be a way to hard-code the captures virtual h/w .

        also another disadvantage, and again , im only referring to my setup here…
        theoretically if i needed the capture to be at full scale from the render globals lets say 2k and my screen would not support such resolution , i would not be able to do a snapshot that size.

        still, its an awesome way . thanks for posting it and for the quick reply


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