Go to: Synopsis. Return value. Flags. Python examples.
cmdFileOutput([close=uint], [closeAll=boolean], [open=string], [status=uint])
Note: Strings representing object names and arguments must be separated by commas. This is not depicted in the synopsis.
cmdFileOutput is undoable, queryable, and NOT editable.
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.
int | : On open, returns a value (descriptor) that can be used to query
the status or close the file. Otherwise, a status code
indicating status of file |
In query mode, return type is based on queried flag.
close, closeAll, open, status
Long name (short name) |
Argument types |
Properties |
|
close(c)
|
uint
|
|
|
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)
|
boolean
|
|
|
open(o)
|
string
|
|
|
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.
In query mode, this flag needs a value.
|
|
status(s)
|
uint
|
|
|
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.
|
|
Flag can appear in Create mode of command
|
Flag can appear in Edit mode of command
|
Flag can appear in Query mode of command
|
Flag can have multiple arguments, passed either as a tuple or a list.
|
import maya.cmds as cmds
cmds.cmdFileOutput( o='dbOutput.txt' )
# Result: 1 #
print( 'This message is in the file\n' )
# This message is in the file
cmds.cmdFileOutput( s=1 )
# Result: 0 #
cmds.cmdFileOutput( s=2 )
# Result: -3 #
cmds.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 = cmds.cmdFileOutput( q=True, o=traceFile )
if -1 != descriptor:
cmds.cmdFileOutput( close=descriptor )