pymel.core.system.cmdFileOutput

cmdFileOutput(*args, **kwargs)

This command will open a text file to receive all of the commands and results that normally get printed to the Script Editor window or console. The file will stay open until an explicit -close with the correct file descriptor or a -closeAll, so care should be taken not to leave a file open. To enable logging to commence as soon as Maya starts up, the environment variable MAYA_CMD_FILE_OUTPUT may be specified prior to launching Maya. Setting MAYA_CMD_FILE_OUTPUT to a filename will create and output to that given file. To access the descriptor after Maya has started, use the -query and -open flags together.

Flags:
Long name (short name) Argument Types Properties
close (c) int ../../../_images/create.gif
 
Closes the file corresponding to the given descriptor. If -3 is returned, the file did not exist. -1 is returned on error, 0 is returned on successful close.
closeAll (ca) bool ../../../_images/create.gif
 
Closes all open files. Flag can have multiple arguments, passed either as a tuple or a list.
open (o) unicode ../../../_images/create.gif ../../../_images/query.gif
 

Opens the given file for writing (will overwrite if it exists and is writable). If successful, a value is returned to enable status queries and file close. -1 is returned if the file cannot be opened for writing. The -open flag can also be specified in -query mode. In query mode, if the named file is currently opened, the descriptor for the specified file is returned, otherwise -1 is returned. This is an easy way to check if a given file is currently open.

status (s) int ../../../_images/create.gif ../../../_images/query.gif
 

Queries the status of the given descriptor. -3 is returned if no such file exists, -2 indicates the file is not open, -1 indicates an error condition, 0 indicates file is ready for writing.

Derived from mel command maya.cmds.cmdFileOutput

Example:

import pymel.core as pm

pm.cmdFileOutput( o='dbOutput.txt' )
# Result: 1 #
print( 'This message is in the file\n' )
# This message is in the file
pm.cmdFileOutput( s=1 )
# Result: 0 #
pm.cmdFileOutput( s=2 )
# Result: -3 #
pm.cmdFileOutput( c=1 )
# Result: 0 #
# Notice that the 'This message is in the file' string is in the file,
# as are all of the entered commands and the
# '# Result: ...' lines, etc.

# Turn on logging to a file on Maya startup so as to log all error
# messages which happen on startup.
#
# Set the environment variable MAYA_CMD_FILE_OUTPUT to "trace.txt"
# Start up Maya
# Messages should now be logged to the file "trace.txt" as well as the
# script editor window.

# Turn off logging to the filename specified by $MAYA_CMD_FILE_OUTPUT
# after Maya has completed startup.
#
import os
traceFile = os.environ[ "MAYA_CMD_FILE_OUTPUT" ]
descriptor = pm.cmdFileOutput( q=True, o=traceFile )
if -1 != descriptor:
    pm.cmdFileOutput( close=descriptor )

Previous topic

pymel.core.system.clearCache

Next topic

pymel.core.system.convertUnit

Core

Core Modules

Other Modules

This Page