Maya 2022 and sys.__stdout__.write

Maya 2022 and sys.__stdout__.write

negow
Advocate Advocate
2,575 Views
4 Replies
Message 1 of 5

Maya 2022 and sys.__stdout__.write

negow
Advocate
Advocate

Hi all,

 

I'm missing the ability to print to the Output Window from Maya 2022, like I could in 2020 and below.

 

My primary use and what I miss the most is "clearing" the output window, when I'm particulatly keen on what message comes next in a series of similar messages.

 

import sys
for emptyline in range(50):
    sys.__stdout__.write("\n")

 

For completenss, __stdout__ is Python's original sys.stdout, used in cases where someone overwrites it like Maya does to instead print to the Script Editor.

 

sys.stdout
# Result: <maya.Output object at 0x0000020B4AF819F0> #

 

Is there another way of writing to the Output Window?

0 Likes
Accepted solutions (2)
2,576 Views
4 Replies
Replies (4)
Message 2 of 5

e_honda
Enthusiast
Enthusiast
Accepted solution

Hi,

Using Maya 2022 in Python 3 mode, the only way I could write to Output Window was using a MEL function.

There should be a better way to solve the problem, but I could not find it.

from maya import mel
mel.eval('trace "write directly to Output Window\n"')

Hope it helps. 

0 Likes
Message 3 of 5

negow
Advocate
Advocate

Thanks, this helps!

0 Likes
Message 4 of 5

WindXu
Alumni
Alumni
Accepted solution

@negow @e_honda This is actually a Python 3 buffering issue.

You can workaround it by calling sys.__stdout__.flush() at the end of your script.

The following script should work for you.

import sys
for emptyline in range(50):
    sys.__stdout__.write("\n")
sys.__stdout__.flush()

 

Thanks

Message 5 of 5

negow
Advocate
Advocate

Thanks @WindXu that does make sense!

0 Likes