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.

OpenMaya 2.0 - saving thumbnail

OpenMaya 2.0 - saving thumbnail

Anonymous
Not applicable
1,009 Views
2 Replies
Message 1 of 3

OpenMaya 2.0 - saving thumbnail

Anonymous
Not applicable
  • Hi, I'm looking for help with  OpenMaya 2.0, I am trying to save a picture of my viewport in 1920x1080, but when I take the picture with this script, it export the image in the good dimension but the thumbnail is not adapted for the format.

 

The script :

 

import maya.api.OpenMaya as om
import maya.api.OpenMayaUI as omUI


image = om.MImage()
image.create(1920, 1080)

view = omUI.M3dView.active3dView()
view.pushViewport(0, 0, 1920, 1080)
view.refresh()
view.readColorBuffer(image, True)

view.popViewport()


image.writeToFile("C:\tmp\test.jpeg", outputFormat="jpeg" )

 

My maya :

Capture d’écran 2021-06-19 152727.png

 

The result :

oui.jpeg

 

If anyone know how to fix this problem, they are welcome

 

Thank you !

0 Likes
Accepted solutions (1)
1,010 Views
2 Replies
Replies (2)
Message 2 of 3

negow
Advocate
Advocate
Accepted solution

The problem is the "active 3d view", the one that's very tall but not very wide in your screenshot, isn't in the dimensions you want. You'll need a new panel with the proper dimensions in order to write out the contents.

 

There's an example of how to accomplish it using Maya's native playblast tool (which can also save single-images) here.

 

- https://github.com/mottosso/maya-capture

 

For example.

 

 

capture(width=1920, height=1080)

 

 

Pay special attention to how it's opening a new panel (viewport) to pull that off.

 

Another much easier option would be to use:

 

 

cmds.playblast(offscreen=True)

 

 

Along with `height` and `width` arguments. That will do all of this for you, without a temporary panel appearing. This isn't using API 2.0 as per the question. To do it that way, you do need a new panel ahead of calling your original code.

0 Likes
Message 3 of 3

Anonymous
Not applicable

Thank you for your answer !
As you say I actually use the playblast function to do it.

I am trying with openMaya just for learning it, but as i can see, this is not the best way...

Thank you I will try to apply your advice with the api !

0 Likes