pymel.core.general.commandPort

commandPort(*args, **kwargs)

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.

Flags:
Long name (short name) Argument Types Properties
bufferSize (bs) int ../../../_images/create.gif
 

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) bool ../../../_images/create.gif
 
Closes the commandPort, deletes the pipes
echoOutput (eo) bool ../../../_images/create.gif
 
Sends a copy of all comand output to the command port. Typically only the result is transmitted. This option provides a copy of all output.
listPorts (lp) bool  
   
name (n) unicode ../../../_images/create.gif
 

Specifies the name of the command port which this command creates. CommandPort names of the form namecreate a UNIX domain socket on the localhost corresponding to name. If namedoes not begin with “/”, then /tmp/nameis used. If namebegins with “/”, namedenotes the full path to the socket. Names of the form :port numbercreate an INET domain on the local host at the given port.

noreturn (nr) bool ../../../_images/create.gif
 

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) bool ../../../_images/create.gif
 
Python output will be pickled.Flag can appear in Create mode of commandFlag can have multiple arguments, passed either as a tuple or a list.
prefix (pre) unicode ../../../_images/create.gif
 

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) bool ../../../_images/create.gif
 

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 noreturnflag is specified.

securityWarning (sw) bool ../../../_images/create.gif
 
Enables security warning on command port input.
sourceType (stp) unicode ../../../_images/create.gif
 
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”.

Derived from mel command maya.cmds.commandPort

Example:

import pymel.core as pm

import maya.cmds as cmds

# Open a command port with the default name "mayaCommand".
pm.commandPort()

# Close the command port with the default name. Open client connections
# are not broken.
pm.commandPort( cl=True )

# Query to see if the command command port "mayaCommand" exists.
pm.commandPort( 'mayaCommand', q=True )
# Result: False #

Previous topic

pymel.core.general.commandEcho

Next topic

pymel.core.general.condition

Core

Core Modules

Other Modules

This Page