Skip to content

Activate Deactivate Command Ports in Maya

Eriks Vitolins edited this page Sep 1, 2014 · 3 revisions

I wrote this before seeing the "Maya Port Switch" solution. FWIW, instead of a toggle, I've provided generic methods for activating/deactivating commandPorts.

import maya.cmds as cmds

def activateCommandPort(host, port, type):
    path = host + ":" + port
    active = cmds.commandPort(path, q=True)
    if not active:
        cmds.commandPort(name=path, sourceType=type)
    else:
        print("%s is already active" % path)

def deactivateCommandPort(host, port):
    path = host + ":" + port
    active = cmds.commandPort(path, q=True)
    if active:
        cmds.commandPort(name=path, cl=True)
    else:
        print("%s is was not active" % path)

#Examples
activateCommandPort('127.0.0.1', '7001', 'mel')
activateCommandPort('127.0.0.1', '7002', 'python')
deactivateCommandPort('127.0.0.1', '7001')
deactivateCommandPort('127.0.0.1', '7002')
Clone this wiki locally