Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

Maya 2016. Grabbing M3dView with python

Maya 2016. Grabbing M3dView with python

Anonymous
Not applicable
732 Views
1 Reply
Message 1 of 2

Maya 2016. Grabbing M3dView with python

Anonymous
Not applicable

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.

 

PS2. While writing this post I've found out that it's not working only if you have Viewport 2.0 set as a renderer. With Legacy mode it works just fine.

0 Likes
733 Views
1 Reply
Reply (1)
Message 2 of 2

Anonymous
Not applicable

A friend of mine confirmed to me that it works in both legacy and 2.0 in Maya 2014 so that's Maya 2016 bug I think.

0 Likes