Maya Open/Close CommandPort

This is a pretty popular code snippet that i am rather reposting for my own sake, as i always have to google for it online, and i find some of the code being modified here and there, so i am posting my own version on my own blog. that i have modified for my own purposes 🙂 and if anyone happens to see this: enjoy 🙂
 

import maya.cmds as cmds
# Close ports if they were already open
try: cmds.commandPort(name=":7001", close=True)
except: cmds.warning('Could not close port 7001')
try: cmds.commandPort(name=":7002", close=True)
except: cmds.warning('Could not close port 7002')
# Open ports
try: cmds.commandPort(name=":7002", sourceType="python")
except: cmds.warning('Could not Open port 7002')	
try: cmds.commandPort(name=":7001", sourceType="mel")
except: cmds.warning('Could not close port 7001')
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s