Using rehash for MEL scripts and import for Python scripts in Maya

I’ve only put up one instructional video and already I need to make a correction.  In my previous post I said that the rehash MEL command would load any scripts that have been dropped into Maya’s scripts folder.  It turns out, that’s only half true.  It works for MEL scripts, but not Python scripts.

If you’re loading a MEL script, or several, just put them in the correct folder, type ‘rehash’ into the MEL command line or script editor:
MEL script(s) will now be sourced by Maya, meaning you only have to follow the instructions that come with the individual scripts to run them.

With Python it is a little trickier, but not bad.  First you need to import.  Switch to the Python command line or go to a Python tab in the script editor, then type “import <filename>”  In this case, or test file is  You can leave the .py off, so your input should look like this:

Once your script is imported, you can then run commands from it.  This time you’ll type <filename>.<command>.  For our test, they are the same, so the command is pythonTest.pythonTest().  Note that you’ll need the parentheses for this one, but you don’t in MEL.

One bothersome thing about the Python scripts is that they have to be reloaded each time you start Maya.  This is easy to work with, though.  If you have a script you use a lot, just make a button that has the import command on one line and the function you want to call on the second line.  Here is what it looks like for my example.
Now just middle-mouse-drag that text to the shelf and you’ll have yourself a button that will import and run the command any time you want.