My stuff and stuff...

Monday, February 11, 2013

I've always believed that clarity should trump brevity when it comes to scripting. This is especially true of Python, since it's already so readable. That's why some things I've written area little longer than they really need to be. However, if I stumble across a way to keep things brief and readable, I try to use it as often as possible.

For instance, in Maya with Python this is how you check for a window and delete it if it exists:

if mc.window(winName, exists = True): mc.deleteUI(winName)

But you could do the same thing with less typing:

try: mc.deleteUI(winName)except: pass

I also like to check the version of Maya that the user is using to avoid conflicts and such. I like dockable UI's but versions of Maya older than 2011 can't support them. So if the user has Maya 2011+, the will dock, otherwise it will float. I've been doing it like this: