Friday, January 25, 2013

Python append to path tool

Here is a little script that allows you to browse for and select paths to add to your sys.path list for python.
I generally don't keep my python scripts (at least the ones I write myself) in my scripts folder, I keep them in one of a couple "Git" folders that allow me to easily load/sync my scripts over GitHub so I can work on them on various computers (I suppose I could arrange things so that my scripts stay separate from all the other script in my scripts folder and point Git there, but I don't).
This works fine for me, but it's a bit a pain to have to keep pointing Maya there to look for my Python scripts. Up til I wrote this script I just wrote a little bit of python code in Maya to append to my sys.path and just copied that to the shelf. No problem. Unless I'm on another computer at home or at a studio. Still not a big deal, but I still have to put the scripts somewhere and point Maya there, and when I'm at a studio I often have stuff in a few places (desktop, folder on the desktop, etc). And I'm so lazy that I think it's a pain to grab the path name to add it to the "sys.path.append(pathName)" in Maya (especially on a Mac). So I wrote this.

Basically, it has two parts (the two tabs). The first part lets you browse for up to three paths and then add em with a click. It dummy checks that a) you've added something and b) what you've added is actually a path that exists.

The second tab is just a quick list of the paths that Maya is currently looking in, it refreshes once you've added new paths or you can manually refresh it if you've added paths elsewhere. Since I didn't want to make this window soooo big that it could catch any potential long path names, if you double click on a path in the "View Paths" tab, it will print that name in the script editor.

There's also the option in the menu bar to save out your entered paths (it will write a "zbw_appendPathSave.txt" file to your user prefs folder). You can then load it later to save some time (it will just overwrite itself if necessary) and it will reload the paths you've browsed for.

Here's a link to the script or it's in the NEW downloads section above. (note: slowly but surely I'll get the other scripts up there too)
Basically, I just drop this in my scripts folder (it's the only python script I keep there, except for stuff that might point Maya elsewhere) and run it from my shelf. Here's the code to do call the script (obviously python):

import zbw_appendPath

Hope it's useful to someone as lazy as me!

No comments:

Post a Comment