How to run scripts, source scripts, and make buttons in Maya

This is an extremely introductory lesson. If you’re familiar with using scripts already, you probably don’t need to read or watch.

I’m starting with a fresh install of Maya 2017 so you can see in these lessons how I set it up to accommodate my workflow.  First I’m going to take care of a couple of quick things that I always forget.  I’m going to turn on autokey:

And I’m going to change my undo queue in settings from the default 50 to infinite:

Alright, now lets talk about scripts.  There are two types we’re going to deal with, code snippets that run inside Maya, and sourced scripts that are stored externally.

This button will bring up your script editor:script-editor-icon

Once open, you’ll see tabs on the bottom half of the window, one for mel one for maya.  When you download a script you’ll know which is which because the file name will end in ‘.mel’ or .’py’.  Right now we don’t have to worry about it.  You can see I’ve entered a line of code into the mel window.  To run this code, highlight it and then click the execute button (it’s under the mouse and looks like a play button) or hit ctrl+enter.

Another way to run a line of code is to enter it into the command line at the lower left.  Right now it is primed to accept mel commands, but if you click where it says ‘MEL’, it will toggle between mel and python.  Enter your command and hit enter.  If you click so your cursor is in the text field, you can also use the up arrow to navigate back to previous commands.

To save some code as a shelf button, highlight it and middle-mouse drag it to the shelf.

To source scripts, you need to put them in your Maya folder.  By default it can be found here (according to my own experience or Google.  If it’s not there on a Max or Linux machine, you might have to look around:
Windows – C:\Users\<username>\Documents\maya
Mac – /Users/Shared/Autodesk/Maya
Linux – /usr/people/<username>/maya

From there you can put a script into the scripts folder if you’d like it to be accessible to all versions of Maya you have installed.

If you want to have the script only accessible to one version of Maya, click on the folder corresponding to the version you’re using and put it in the scripts folder there, or prefs/scripts.   Either should work. For example:

A downloaded script will usually have a readme with instructions or instructions embedded in the code.  Open it with any code editor and look at the top for instructions.  For this example I’ve highlighted the pertinent information.

For your newly placed script to be visible to Maya, you either need to close and restart the program or type the command ‘rehash’ into the MEL command line.*   After that just follow the instructions to get things started.  In this case type ‘arctracker108’ into the command line and the scripts GUI should appear.  If you highlight and middle-mouse drag that text to a shelf, you now have a button that will load the arctracker108 script any time you need it.

You can try this out with any script, but if you want to use the same specific one, you can find it here:

That’s it for today.  The last major way to run scripts is with hotkeys, which I’ll be going over next time.

*UPDATE: the ‘rehash’ command only works to refresh MEL scripts.  Python scripts must be imported differently and that is covered in the next lesson

One thought on “How to run scripts, source scripts, and make buttons in Maya

Leave a Reply

Your email address will not be published. Required fields are marked *