4. The code that is of interest to us is this:
hyperShadePanelMenuCommand("hyperShadePanel1", "createNewNode");
editMenuUpdate MayaWindow|mainEditMenu;
5. With your middle mouse button (MMB), drag this in the Script
Editor’s input area and execute it. The Create Render Node
window should appear.
6. Using the MMB, drag these two lines to the shelf.
7. Now you can open the Marking Menu window and create a
marking menu like you normally would.
1.3.3 Maya as a System of Nodes
To make the transition from GUI to scripting a bit easier, the single
most important thing you have to understand is that:
Maya is a system of nodes with attributes that can be
connected and animated. This system is called the
“dependency graph.”
My good friend Tom Kluyskens always compares Maya with a set of
LEGO blocks. One block (node) can be independent and have some
characteristics (attributes) such as its color, shape, weight, etc., but
things start getting interesting when you put those separate blocks
(nodes) together to build something.
Knowing that a scene is nothing more than a collection of nodes
and connections is paramount when scripting. Often the UI hides
most of what happens in the dependency graph, but when scripting
you will have to delve right into it. Hence a firm understanding is
essential.
Every part of a Maya scene (be it a texture, camera, expression,
or geometry) is internally represented as a node. Each node has
attributes, which store the characteristics of that specific node. As
mentioned before, the system of these nodes, their attributes, and
the connections in between is called the dependency graph. Often,
to write a MEL script to automate a task, you will look at what
Under the Hood
13
Chapter 1
happens in the dependency graph and then reproduce it in MEL for
your specific purpose.
We all know you can manipulate the keyable attributes of a node
in the channel box, and most of the other attributes in the Attribute
Editor. I say most attributes, because certain attributes can only be
accessed through MEL.
Using the Graph Editor, let’s take a closer look at the depend-
ency graph of a simple scene like an animated ball.
1. With the Hypergraph and Attribute Editor open, create a
NURBs sphere.
2. In the Hypergraph you can see that several nodes were cre-
ated. (Like the flow of a river, nodes whose attributes’ values
connect to the current node are “upstream” nodes, and nodes
that connect to the current node are “downstream” nodes.)
n
nurbsSphere1: This is the transform node. The attributes
of a transform node store all the information of where an
object is in space (world and local) and how it is scaled and
rotated.
n
nurbsSphereShape1: This is the shape node. The shape
node contains a node’s actual geometric shape and the
properties about its construction and rendering.
n
initialShadingGroup: This is a shading group node that
contains all objects that will be shaded with that particular
shader.
3. If you hold your cursor over the connections, you can see
which attributes of which nodes are connected.
4. Set some keyframes on the sphere.
Chapter 1
14
Figure 1-11
Setting a keyframe on a node (now represented as a trapezoid
in the Hypergraph) connects an animation curve to each chan-
nel that is getting animated. When you play back the scene,
Maya’s time1 node (the scene’s clock), tells the animation
curve which frame’s numbers value to look up. Then the ani-
mation curve sets (in this particular case) the translate value
to the right value.
5. Click on the sphere in the Hypergraph (HG) and choose Show
up and downstream connections.
6. Hold your mouse over the connections to get a clear idea of
what is going on.
Now let’s examine a more “elaborate” example: a joint hierarchy
bound to a cylinder.
By the way, to get detailed information about nodes and their
attributes, go to Help > Developer Resources > Nodes and
Attributes.
Under the Hood
15
Chapter 1
Figure 1-12
1. With the HG open, create a cylinder, put three joints inside,
and Smooth Bind.
2. From left to right (upstream to downstream) let’s take a look
at what is going on:
n
On the far left we have the polyCylinder history node con-
nected to the original cylinder’s shape node, which has
been renamed and hidden. (Hidden nodes are grayed out.)
n
tweak1 is a tweak node, which is automatically created
when you perform any kind of deformation. A tweak node
Chapter 1
16
Figure 1-13: The Developer Resources Nodes help page
Figure 1-14

Get Professional MEL Solutions for Production now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.