Skip to content

Instantly share code, notes, and snippets.

@justsh
Created August 31, 2024 07:55
Show Gist options
  • Select an option

  • Save justsh/9321fc74c9a766e7723c120e86bf936e to your computer and use it in GitHub Desktop.

Select an option

Save justsh/9321fc74c9a766e7723c120e86bf936e to your computer and use it in GitHub Desktop.
Wrap pm.commandPort with defaults set for the MayaSublime plugin
from __future__ import print_function
import pymel.core as pm
def openPort(port=":7002", **kwargs):
print("Opening command port", port)
commandPortWrapper(port, False, **kwargs)
def closePort(port=":7002", **kwargs):
print("Closing command port", port)
commandPortWrapper(port, True, **kwargs)
def commandPortWrapper(port=":7002", close=False, **kwargs):
# the default port is set for the justinfx/MayaSublime plugin
if not port.startswith(':'):
port = ''.join([':', port])
if "sourceType" not in kwargs:
# assume python, instead of the maya default, which is to assume mel
kwargs["sourceType"] = "python"
if not close:
if "noreturn" not in kwargs:
kwargs["noreturn"] = True
if "echoOutput" not in kwargs:
kwargs["echoOutput"] = True
kwargs["close"] = False
else:
kwargs["close"] = True
try:
pm.commandPort(name=port, **kwargs)
except RuntimeError as e:
print(e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment