Hi!
I’m having this problem with Maya M3dView class. I’m creating a super simple widget with this code:
def get_preview_window():
win = cmds.window()
layout = cmds.paneLayout()
model_editor = cmds.modelPanel()
cmds.setParent("..")
cmds.setParent("..")
cmds.showWindow(win)
get_preview_window()
Now I’m trying to grab a screenshot from this with this code:
import ctypes
import maya.OpenMaya as om
import maya.OpenMayaUI as omui
from PySide.QtGui import QImage
view = omui.M3dView.active3dView()
width = view.portWidth()
height = view.portHeight()
img = om.MImage()
view.readColorBuffer(img, False)
ptr = ctypes.cast(img.pixels().__long__(), ctypes.POINTER(ctypes.c_char))
ptrAsStr = ctypes.string_at(ptr, width * height * 4)
qimg = QImage(ptrAsStr, width, height, QImage.Format_ARGB32)
qimg = qimg.mirrored(horizontal=False, vertical=True)
qimg.save('C:/screenshot.png')
Now - the thing is that the grabbed image has a proper size of an embedded viewport (the one created with mel) but the actual image comes from the main viewport (“modelPanel4”) so it’s cropped and it’s completely not what I want.
Can anyone help me with that?
PS. One IMPORTANT thing - it stops to work when you open the viewport window, navigate it and then try to grab it. If you grab it right after creation everything works just fine.