Skip to content

Error saving pose thumbnail #24

Description

@ryanzujic

We were having an issue where any attempt to save a pose would result in a standard error.
I traced this down to Red9_General.thumbnailApiFromView()
From what I understand, the issue was that the function is written as:

thumbnailApiFromView(filename, width, height, compression='bmp', modelPanel='modelPanel4'):

This default argument given for modelPanel refers to a panel that doesn't always exist / isn't what we want.

In the studio we've updated this logic and added another function we use for grabbing active model panels and it seems to have sorted it. Sorry I'm not super familiar with the standard feedback process for developers on GitHub, but hopefully this is useful!

(We've also updated it to clean up panel elements that aren't useful for the thumbnail with the polygonsOnly flag. We don't have any occasions where we want anything other than polygons visible in the thumbnail but that may not be universally true for others)

def thumbnailApiFromView(filename, width, height, compression='bmp', modelPanel=None, polygonsOnly=True):
    '''
    grab the thumbnail direct from the buffer?
    TODO: not yet figured out how you crop the data here?
    '''
    import maya.OpenMaya as OpenMaya
    import maya.OpenMayaUI as OpenMayaUI

    view = None

    # If we didn't get a model panel or the one supplied doesn't exist, make a best guess with what's available
    if not modelPanel or not cmds.panel(modelPanel, ex=True):
        modelPanel = returnBestGuessModelPanel()

    # Clean up the panel before creating a thumbnail
    if polygonsOnly:
        cmds.modelEditor(modelPanel, e=True, allObjects=False)
        cmds.modelEditor(modelPanel, e=True, polymeshes=True)
        cmds.modelEditor(modelPanel, e=True, sel=False)

    view = OpenMayaUI.M3dView()
    OpenMayaUI.M3dView.getM3dViewFromModelEditor(modelPanel, view)
    OpenMayaUI.M3dView.refresh(view)

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

    # Show all objects in the panel if we hid them
    if polygonsOnly:
        cmds.modelEditor(modelPanel, e=True, allObjects=True)
        cmds.modelEditor(modelPanel, e=True, sel=True)

    log.info('API Thumbname call path : %s' % filename)

def returnBestGuessModelPanel():
    # Get all model panels
    modelPanels = cmds.getPanel(typ="modelPanel")
    panelWithFocus = cmds.getPanel(wf=True)
    # If the panel with focus is a model panel, use it, otherwise use the first model panel available
    if panelWithFocus in modelPanels:
        return panelWithFocus
    else:
        return modelPanels[0]

Thanks for all of your hard work on this tools package, it's been hugely useful and appreciated over the years.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions