Class 4: Sample MEL scripts, part 1
Deconstructing existing programs

What follows are a couple of programs each from the areas of modeling, animation and rendering. Play with each one for a bit, then analyze it for the following: By analyzing and adapting ("embrace, extend") existing programs you can start to develop your own bag of tricks, your own style and eventually, your own mastery of MEL.
Nodes, connections

Underneath it all, a Maya scene is a collection of 'nodes' (that store data), hooked together via 'connections' using the nodes' 'attributes'.

So a lot of MEL programming understandably has to do creating/deleting nodes, creating/deleting node attributes, getting/setting attribute values, connecting/disconnecting attribute connections.

In addition to dealing with nodes, MEL programming also has to do with the following (which ultimately still involve nodes and their attributes):






v_shaker [and v_shaker_better]


Here is a way to rename materials:

string $newName = "New_Name";

string $removeMat[] = {"lambert1", "particleCloud1", "initialShadingGroup", "initialParticleSE"};

string $materials[] = stringArrayRemove($removeMat,`ls -mat`);

for($material in $materials)
      rename $material $newName;
      print ("Renaming " + $material + "\n");


Create a scene with some surfaces and a dir. light, choose 'lambert1' in your scene, then run:

abDropSpotCam - creates a light or camera at current viewcam's location.
abDropSpotCam <0|1|2|3|4>; // 0 or 1 or 2 or 3 or 4

Create a paintable surface, select it, choose a brush, then run:
paintRandom 10 10 1 0 10 0 1 0;