print to show up right of the command line

2,740 views
Skip to first unread message

yury nedelin

unread,
Aug 14, 2008, 3:05:34 PM8/14/08
to python_in...@googlegroups.com
hey is there a way to have python print into the field right of the command line in Maya as it does if you print in mel?

thanks
Yury



NPuetz

unread,
Aug 14, 2008, 3:54:28 PM8/14/08
to python_inside_maya
import sys

sys.stdout.write('Hello World!')

yury nedelin

unread,
Aug 14, 2008, 4:49:46 PM8/14/08
to python_in...@googlegroups.com
awesome
thanks

Yury

JakobWelner

unread,
Aug 24, 2008, 12:18:27 PM8/24/08
to python_inside_maya
Pythons 'print' works just as well for that purpose but you have to
escape the newline by ending the print with a comma
Eg:
print "something on the command output line",

Printing like Mayas "error" and "warning" with the colored background
is something I haven't found out how to do though.

John Riddle

unread,
Aug 24, 2008, 2:50:41 PM8/24/08
to python_in...@googlegroups.com
import maya.mel as mel
mel.eval('warning "yada yada"')

yury nedelin

unread,
Aug 25, 2008, 1:25:08 PM8/25/08
to python_in...@googlegroups.com
thats a great trick thanks

yury

On Sun, Aug 24, 2008 at 9:18 AM, JakobWelner <jakob....@gmail.com> wrote:

Simon

unread,
Aug 25, 2008, 1:39:36 PM8/25/08
to python_in...@googlegroups.com
you might want to use the "displayError"-API-class

it works like this :
---------------------

import maya.OpenMaya as om
om.MGlobal.displayError("Nothing Selected")
om.MGlobal.displayWarning("This is a warning")


yury nedelin

unread,
Aug 25, 2008, 2:30:34 PM8/25/08
to python_in...@googlegroups.com
haha wow do many ways to choose from

I have not got to using any  API in  python yet but this could be a nice way to start

Clemens

unread,
Aug 25, 2008, 4:17:12 AM8/25/08
to python_inside_maya
Just to keep this little "ways of printing" collection complete:

import maya.OpenMaya as om
om.MGlobal.displayInfo("my grey info message")
om.MGlobal.displayWarning("my pink warning")
om.MGlobal.displayError("my red error message")

What I'm still missing is a way of printing to the Output Window.
Does anyone know a better way than calling mel?
import maya.mel as mel
mel.eval('trace "my log message"')

All best wishes
Clemens

Dean Edmonds

unread,
Aug 26, 2008, 9:05:06 AM8/26/08
to python_in...@googlegroups.com
On Mon, Aug 25, 2008 at 1:17 AM, Clemens <cle...@gmx.de> wrote:
>
> What I'm still missing is a way of printing to the Output Window.
> Does anyone know a better way than calling mel?

import sys
sys.__stdout__.write('hello world\n')

--
-deane

Clemens

unread,
Aug 27, 2008, 4:45:42 PM8/27/08
to python_inside_maya
> import sys
> sys.__stdout__.write('hello world\n')
Great, thank you!
Now I see, this means the python interpreter redirects stdout to the
script editor's history.
So I might reset stdout back to the output window if I like.
sys.stdout = sys.__stdout__
I've been wondering why userSetup.py prints to the output window while
userSetup.mel prints to the script editor.
This makes it a bit clearer now: I guess redirection of stdout doesn't
take effect until the interface is built.
But I still wonder why MGlobal.displayInfo() messages in userSetup.py
don't show up at all.

By the way, I have a long delay after submitting a post until it is
published in this group.
My last message in this topic here was sent on Monday morning 10:17 as
you can see.
But it didn't appear until 26 hours later on Tuesday 12:30.
Though submitted later there are three messages appearing before mine.
This makes my message look a bit silly since Simon already gave the
hint to MGlobal.
Am I doing something wrong?
Should I use groups.google.com instead of the German domain
groups.google.de?

All best wishes
Clemens

aaron.c...@epicgames.com

unread,
Jul 28, 2016, 3:34:01 PM7/28/16
to Python Programming for Autodesk Maya
Is there a way to re-direct print output back to the script editor without closing Maya?

yury nedelin

unread,
Jul 28, 2016, 9:05:33 PM7/28/16
to python_in...@googlegroups.com

Do you mean when you run

print("something")

in Python in script editor in maya, it does not print the result in the script editor but only in command line output?

Could you explain in more detail what you are doing.
Yury

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/b4c245a5-e2ba-41f3-86c6-20a2b41b0154%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Aaron Carlisle

unread,
Jul 28, 2016, 9:08:18 PM7/28/16
to python_in...@googlegroups.com

I actually figured it out. Lol :P

Since I was overwriting XStream and redefining stdout I needed to reset stdout to point to Maya's output, but where is that? Well, the hint was staring me in the face, I just needed to find it; the answer was in plogging.py (pymel's logging system). There's a function called _fixMayaOutput and they use it to reset their own logging system. I used similar logic to flush my own system back to Maya's.

So...
import sys
from maya import utils

# redefine sys.stdout
sys.stdout = utils.Output

# in order to use stdout 'write' requires a 'maya.Output' so we flush it
class MayaOutput(sys.stdout):
    def flush(*args, **kwargs):
        utils.Output = MayaOutput()
        sys.stdout = utils.Output

# initialize
log = MayaOutput()

# and flush, we're back to feeding output to the script editor
log.flush()

print("Hello World")


You received this message because you are subscribed to a topic in the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/python_inside_maya/FOJtmJjGDwc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CACqGSch_NPQKwDbcKi%2BKAB%3DmLZxSfDuKV32aVx60fE-%2BXsXptg%40mail.gmail.com.

Paul Molodowitch

unread,
Jul 29, 2016, 1:37:50 PM7/29/16
to python_in...@googlegroups.com
Also - standard prints actually DO get displayed in the command line output... but ONLY if you don't include a trailing newline. So to get stuff to show up to the right, all you need to do is:

print "This will show up!",

(note the trailing comma!)

Of course, this means that results in the script editor window will tend to get jammed together on the same line... so I will often use MGlobal.displayInfo/displayWarning/displayError.  These have the added advantage that they will have fancy color-coding for warning/error:

import maya.OpenMaya as om
om.MGlobal.displayWarning("Oh noes! You haz dun rong!")


One feline, numerous flensing methods...

Reply all
Reply to author
Forward
0 new messages