Maya Python API - Getting Mesh Data Maya Python eval != MEL eval
Dec 16

Just a brief example but say you are doing a task that locks up Maya and you want to get some feedback. Printing to the script editor is not helpful if you are batching files or you have a script that needs to do several tasks before finishing because Maya will not allow you to see the script editor until its finished.

Alternatively to print you can use the MEL trace command which prints to the output window of Maya. This is not a Python command technically and ends up being a bit messy when concatenating strings.

The last method shown I import the sys module and use __stdout__ which mimics C++ cout the most closely.

Another benefit is printing to the Output Window is much faster than printing to the script editor. Printing to the output window can help you debug certain types of scripts easier.

import sys
import maya.mel as mel
import maya.cmds as cmds

dagNodes = cmds.ls( dagObjects=True )

# print nodes in script editor, slow
print "List of nodes in the scene///////////////////////////////////////"
for dag in dagNodes:
	print ('Dag Node: ' + dag)

# print nodes in output window, messy
mel.eval('trace "List of nodes in the scene///////////////////////////////////////";')
for dag in dagNodes:
	mel.eval('trace (\"' + 'Dag Node: ' + dag + '\");')

# print nodes in output window, using Python sys module
sys.__stdout__.write( 'List of nodes in the scene///////////////////////////////////////\n' )
for dag in dagNodes:
    sys.__stdout__.write( 'Dag Node: ' + dag + '\n')

Have fun,
-RyanT

Leave a Reply