Go to: Synopsis. Return value. Flags. Python examples.
commandPort([bufferSize=int], [close=boolean], [echoOutput=boolean], [name=string], [noreturn=boolean], [pickleOutput=boolean], [prefix=string], [returnNumCommands=boolean], [securityWarning=boolean], [sourceType=string])
Note: Strings representing object names and arguments must be separated by commas. This is not depicted in the synopsis.
commandPort is undoable, queryable, and NOT editable.
Opens or closes the Maya command port. The command port comprises a socket
to which a client program may connect. An example command port client
"mcp" is included in the Motion Capture developers kit.
It supports multi-byte commands and uses utf-8 as its transform
format. It will receive utf8 command string and decode it to Maya native
coding. The result will also be encoded to utf-8 before sending back.
Care should be taken regarding INET domain sockets as no user
identification, or authorization is required to connect to a given
socket, and all commands (including "system(...)") are allowed and
executed with the user id and permissions of the Maya user. The prefix
flag can be used to reduce this security risk, as only the prefix
command is executed.
The query flag can be used to determine if a given command port exists.
See examples below.
In query mode, return type is based on queried flag.
bufferSize, close, echoOutput, name, noreturn, pickleOutput, prefix, returnNumCommands, securityWarning, sourceType
Long name (short name) |
Argument types |
Properties |
|
bufferSize(bs)
|
int
|
|
|
Commands and results are each subject to size limits. This option allows
the user to specify the size of the buffer used to communicate with Maya. If
unspecified the default buffer size is 4096 characters.
Commands longer than bufferSize characters will cause the client connection to close.
Results longer that bufferSize characters are replaced with an error message.
|
|
close(cl)
|
boolean
|
|
|
Closes the commandPort, deletes the pipes
|
|
echoOutput(eo)
|
boolean
|
|
|
Sends a copy of all command output to the command port. Typically
only the result is transmitted. This option provides a copy of
all output.
|
|
name(n)
|
string
|
|
|
Specifies the name of the command port which this command
creates. CommandPort names of the form name create a
UNIX domain socket on the localhost corresponding to
name. If name does not begin with "/",
then /tmp/name is used. If name begins
with "/", name denotes the full path to the socket.
Names of the form :port number create an INET domain
on the local host at the given port.
|
|
noreturn(nr)
|
boolean
|
|
|
Do not write the results from executed commands back to the
command port socket. Instead, the results from executed
commands are written to the script editor window. As no information
passes back to the command port client regarding the execution
of the submitted commands, care must be taken not to overflow
the command buffer, which would cause the connection to close.
|
|
pickleOutput(po)
|
boolean
|
|
|
Python output will be pickled.
|
|
prefix(pre)
|
string
|
|
|
The string argument is the name of a Maya command taking one string
argument. This command is called each time data is sent to the command
port. The data written to the command port is passed as the argument to
the prefix command. The data from the command port is encoded as with
enocodeString and enclosed in quotes.
If newline characters are embedded in the command port data,
the input is split into individual lines.
These lines are treated as if they were separate
writes to the command port. Only the result to the last
prefix command is returned.
|
|
returnNumCommands(rnc)
|
boolean
|
|
|
Ignore the result of the command, but return the number of
commands that have been read and executed in this call. This
is a simple way to track buffer overflow. This flag is ignored
when the noreturn flag is specified.
|
|
securityWarning(sw)
|
boolean
|
|
|
Enables security warning on command port input.
|
|
sourceType(stp)
|
string
|
|
|
The string argument is used to indicate which source type
would be passed to the commandPort, like "mel", "python".
The default source type is "mel".
|
|
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
# Open a command port with the default name "mayaCommand".
cmds.commandPort()
# Close the command port with the default name. Open client connections
# are not broken.
cmds.commandPort( cl=True )
# Query to see if the command command port "mayaCommand" exists.
cmds.commandPort( 'mayaCommand', q=True )