Skip to content

Activate Deactivate Command Ports in Maya

Eriks Vitolins edited this page Aug 31, 2014 · 3 revisions

Activate/Deactivate Command Ports in Maya

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(name, port, type):
    path = name + ":" + 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(name, port):
    path = name + ":" + 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