Skip to content
Kumaran edited this page May 21, 2014 · 2 revisions
import maya.cmds as cmds

def openPort(portNumber=None):
    if portNumber is None:
        portNumber = ":7002"
    if cmds.commandPort(portNumber, q=True):
        print "Port {0} is open, attempting to close".format(portNumber)
        cmds.commandPort(name=portNumber, cl=True)
        print "Port {0} now closed!".format(portNumber)
    else:
        print "Port {0} is closed, attempting to reopen".format(portNumber)
        cmds.commandPort(name=portNumber, sourceType="python")
        print "Port {0} now open!".format(portNumber)

openPort()
Clone this wiki locally