As you are working on your Maya scene, you may encounter moments that are worth taking a snapshot of: for reference, to track your progress, or for versioning - as you save different versions of your scene, you can quickly browse through the previews instead of opening the project.
Here is a simple python script that you can use to take snapshots of your active viewport, by leveraging Maya's playblast feature. The previews are then saved in a folder next to your current scene file.
The script is available below and on our Github page here:
Keep reading for a Code Overview or, to use it right away, simply paste the script below in a new shelf item directly in Maya: Creating Shelf Items.
Code Overview
This section should rapidly get you up to speed on what the script does.
Image Dimensions
For convenience, the image dimensions are placed at the top. Here you can specify the width and height of the playblast image.
Note: The size of the image is capped at the width and height set in the scene's Render Settings panel. The default is 960 x 540.
Panels and cameras
Since the playblast command renders the active panel, we have to check whether the active panel is actually a viewport. The technical name for a viewport in Maya is: modelPanel.
If we have the correct panel we can then retrieve the active camera.
We can then customize the folder path. In our case we added -prv/.
Our folder path is then passed to the makedirs command to create the actual folder - right next to the scene file.
The full path will instead be specified in the playblast command to define the image output.
Note: We used the .jpg extension. Make sure to change this if you specify a different output image format in the playblast command.
Playblast Command
A playblast is simply a preview generated from the active viewport. The tool is accessible from Windows > Playblast in Maya. By default it takes the settings from the Render Settings > Common Tab. We can override those settings using custom flags/options.
First make sure you have the shelf enabled. You can turn it on here: Windows > UI Elements > Shelf.
With the shelf open, locate the settings cog icon and choose the shelf editor...
In the shelf editor you can create a new shelf or add a new item to an existing one. To add a new item simply choose the new item button and rename the shelf item.
Head over to the Command tab, select Python as the source language and paste in the script.
Note: The shelf items are automatically saved for the current scene when you make changes. You may want to ensure the shelves are saved to the Maya preferences by manually choosing the Save All Shelves button.
Customizing Shelf Items
You can customize the look by choosing an icon. You can upload or choose one from the built in factory icons.
Write a description of what the shelf item does in the Tooltip field.