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

Clean code

In a desperate search for advanced programming tutorials , my co-worker Igor had suggest a great reading material, by Robert C. Martin – “Clean Code”.

While this book is based around Java, it does not stop me from applying the same principles for my python development.

So far,  am almost at the end of the book, around chapter 12, but already had used an saw great improvement with my current projects. I now look back at my old code, and think GOSH… how could i even write that ? But we had all been there before, and this is a great way to see progress.