Maya’s Definition of a scriptNode:
scriptNodes contain scripts that are executed when a file is loaded or when the script node is deleted.
Steve’s Definition of a scriptNode:
scriptNodes are the equivalent of coming home after a long day to find the dinner table set and food waiting for you.
You might think, “I’m not a TD, I don’t work with MEL, why should I care about scriptNodes? What is he talking about?”
Well, let me make it plain. When I work in Maya, I tend to setup my workspace a specific way. I have certain tools that I use time and time again and I like to have them easily accessible and ready to go. This is my preferred setup:
Sure we have shelves, and they are great, but I’d be lying if I said I didn’t feel a certain amount of angst about having to re-open and locate my tools every time I open my scene. This is highlighted when Maya crashes. My blood is boiling and upon opening Maya back up and realizing that I need to setup my workspace again, I get eye twitches.
During one of my fits of rage I realized that my shelf buttons are simply calling bits of MEL script when they are clicked. Wouldn’t it be nice if I could have those scripts run automatically when my scene opens? Enter scriptNodes.
I will create a scriptNode that opens all of my tools when I load my scene file.
Step #1 – Create a new scriptnode
Create a NEW SCENE in Maya (this will allow you, in the future, to import the scriptNode into other projects/scenes without having to rebuild it for each one)
Click on Window > Animation Editors > Expression Editor
This will bring up the Expression Editor, at which point you will want to click on ‘Select Filter’ and choose ‘By Script Node name’
Name your scriptNode and then click on ‘New Script Node’
Be sure that Open/Close is selected on the ‘Execute On’ dropdown. This will tell the scriptNode to run when the file is opened.
The Script section is where you will be writing the scripts that will be executed by the scriptNode. So how do we figure out what we need to write here?
Step #2 – Gathering and entering scripts
**as of today I have yet to figure out how to make scriptNodes work with Python code. When I find a solution I will update this tutorial.**
Right now you probably open your tools with your shelf buttons. I mentioned above that a shelf button is simply running a script when it is pressed. So we can steal the script from the button and copy it into our scriptNode.
Right click on the shelf button for the tool you wish to add to the scriptNode. Select ‘Edit’
The window that pops up now should contain the code. Copy and paste that code into the ‘Script’ section of your scriptNode in the Expression Editor.
Repeat this process, pasting the new code directly after the first code in the scriptNode until you have all of your tools added. When you are finished, close the Expression Editor and save your scene.
That’s it! When you start your next project, import your scriptNode scene into the scene you are working on and save. From then on, your tools will be there waiting for you!
It is useful to note that since a scriptNode can accept any MEL script, there really is no limit to how much you can improve your workflow with scriptNodes and a little creativity.
There are some UI elements you may wish to open with your scriptNode but they don’t have a shelf button and therefore, you don’t know what the MEL code is. I have put a few common and useful ones below.
tearOffPanel “Graph Editor” “graphEditorPanel” true;
tearOffPanel “Hypershade” “hyperShadePanel” true;
tearOffPanel “Outliner” “outlinerPanel” false;