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:
- use of vars, expressions
- flow control - branches, loops
- use of procs and built-in MEL commands, and how they are chained via input/output
- math/CG algorithms where applicable (not all MEL programs need to have these)
- programming 'style' (syntax and semantics)
- overall programming "logic" - how does everything work together to get the job done?
- ways to improve the program - more features? less features? better organization? better use of memory? better algorithms? ANY program can be made better in SOME way!!
- comments - useful? superfluous? verbose? terse?
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):
- grouping, ungrouping, parenting, unparenting
- selecting
- querying/listing scene data
- dealing with the history mechanism (undo/redo)
- file I/O, rendering..
- loading/unloading plugins
- setting up expressions, scriptJobs..
- dealing with user prefs
- UI creation
- other
Rendering
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");
}
colorizeUsingRamp
Create a scene with some surfaces and a dir. light, choose 'lambert1' in your scene, then run:
colorizeUsingRamp;
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
paintRandom
Create a paintable surface, select it, choose a brush, then run:
paintRandom 10 10 1 0 10 0 1 0;