Do you mean the commandLine widget, that has the input on the left and the
output on the right, at the bottom of the main window?
While it does have a background color attribute, it doesn't perform the
same result as when a warning or error is generated (yellow/red).
It just outlines it.
For the screen cap, there are a couple solutions you could use.
A super duper basic way would be to do a viewport playblast to an image,
and then perform whatever cropping you want on the resulting image file:
cmds.playblast( frame=cmds.currentTime(q=True),
f="viewport.png",
fo=True, fmt="image", viewer=False,
c="PNG", quality=70, rfn=True )
Another way would be to use the API to get an MImage of the current
viewport. Nathan Horne has an example of doing this and writing to a file:
http://nathanhorne.com/?p=261
import maya.OpenMaya as om
import maya.OpenMayaUI as mui
image = om.MImage()
view = mui.M3dView.active3dView()
view.readColorBuffer(image, True)
image.writeToFile("viewport.png", "png")
But again, you will need to perform the cropping using your own lib.
And lastly, if you want to perform the entire process before writing to a
file, and you already happen to have PyQt4 installed for Maya, you can
transfer the pixel buffer over to a QImage:
import maya.OpenMaya as om
import maya.OpenMayaUI as mui
import sip
from PyQt4 import QtCore, QtGui
image = om.MImage()
view = mui.M3dView.active3dView()
view.readColorBuffer(image, True)
w,h = view.portWidth(), view.portHeight()
vptr = sip.voidptr(long(image.pixels()))
i = QtGui.QImage(vptr, w, h, QtGui.QImage.Format_RGB32)
trans = QtGui.QTransform()
trans.scale(-1, 1)
trans.rotate(180)
i = i.transformed(trans,
QtCore.Qt.SmoothTransformation).rgbSwapped().copy(0,0,300,200)
i.save("screencap.png")
What this does is gets the pixel array from the MImage, then creates a
QImage from that data directly. The data was in a bit of a different
format, so I had to flip it on X and then rotate it. Also, I needed to swap
the rgb channels into the right order. You can perform the crop you want
using that copy method. It takes the x,y points and the width height.
On Thu, Aug 16, 2012 at 3:40 AM, Florian Croquet <[email protected]> wrote:
> I have another question, in a script I used the command :
> cmds.warning("string" ).
> It's very useful and I'm now looking for something similar but with
> another color.
>
> Do someone know if there is another command which allow to display a
> message in the command window ( in green if possible )
> I tried to find something on the python documentation, but I couldn't find
> anything
>
> I have another thing in mind for a futur script, I would like to take a
> pictures of a model inside maya, a simple print screen but I want print
> only 250*300 pxl of my screen.
> Do you think that it's possible in Python ?
>
>
> Le mercredi 15 août 2012 15:45:56 UTC+2, Florian Croquet a écrit :
>
>> Thank you Justin, it's a very handy trick !
>>
>>
>>
>>
>> Le mardi 14 août 2012 20:24:18 UTC+2, Justin Israel a écrit :
>>>
>>> Here is a little tip. If you turn on History -> Echo All Commands in the
>>> script editor, and perform some operations, you will see it spit out the
>>> MEL it is executing. When you do that and open Export Selected, you will
>>> see it runs a built in command: ExportSelection
>>> This command is available to both the MEL and python side:
>>>
>>> MEL: ExportSelection;
>>> PY: cmds.ExportSelection()
>>>
>>>
>>>
>>> On Tue, Aug 14, 2012 at 1:50 AM, Florian Croquet <[email protected]>wrote:
>>>
>>>> I have another little question,
>>>>
>>>> Is it possible to open this export window with python or mel ?
>>>>
>>>>
>>>> <https://lh5.googleusercontent.com/-xCMg5cEzh_A/UCoRMRhdO6I/AAAAAAAADRM/7wclDxXfDHQ/s1600/screenexport.jpg>
>>>>
>>>> --
>>>> view archives:
>>>> http://groups.google.com/**group/python_inside_maya<http://groups.google.com/group/python_inside_maya>
>>>> change your subscription settings: http://groups.google.com/**
>>>> group/python_inside_maya/**subscribe<http://groups.google.com/group/python_inside_maya/subscribe>
>>>>
>>>
>>> --
> view archives: http://groups.google.com/group/python_inside_maya
> change your subscription settings:
> http://groups.google.com/group/python_inside_maya/subscribe
>
--
view archives: http://groups.google.com/group/python_inside_maya
change your subscription settings:
http://groups.google.com/group/python_inside_maya/subscribe