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.

Write to command response in MEL

Write to command response in MEL

Anonymous
Not applicable
2,072 Views
3 Replies
Message 1 of 4

Write to command response in MEL

Anonymous
Not applicable

Is there a way to write to the Command Response (1 line console window) . I'm not after coloured (warning) text - but that would be nice. Just a the Melonic equivalient to :

 

# writes to Maya Command Response
import sys
cheese = "Gwen Stefani"
sys.stdout.write(cheese)

  

Cheers.

 

 

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

RFlannery1
Collaborator
Collaborator
Accepted solution

To write a plain message, use "print":

$s="Hello There";
print ($s + "\n");

To write a colored warning message, use "warning":

$t="Oh, no!";
warning $t;

There is also a colored error message.  Note that your script will stop executing if it encounters the "error" command:

$u = "Something went really wrong!";
error $u;
print "I will never reach this line of code\n";

Note that with "print", you generally want to include a newline, "\n", at the end of your message.  With "warning" and "error" you don't have to include the newline.

Message 3 of 4

Anonymous
Not applicable

Doh! And there was I looking for a clever solution....

 

I find it odd (and inconsistant) that print in MEL will write to the Command Response, but Python won't. 😐

 

 

0 Likes
Message 4 of 4

RFlannery1
Collaborator
Collaborator

Heh, I never noticed that before.  I knew that you could use "cmds.warning" and "cmds.error" in Python, and those show output in the desired location.  But sure enough, Python's "print" statement only shows the output in the Script Editor.  (And there is no "cmds.print".)

0 Likes