-
a great site dedicated to MEL with an introduction to MEL - http://www.ewertb.com/maya/mel_intro.html
-
the manual - there are two parts in the manual - one is a general description of MEL - and the other one is the MEL Command Reference which documents both the intrinsic MEL commands (like print, match, …) and procedures that are related to the functionality of Maya (like selecting objects in scenes, creating particles, creating cubes, …) - their purpose, syntax and semantics
-
a great place to learn from are the collected MEL scripts on http://www.highend3d.com/maya/mel/
- a script to scatter objects within bounds and the possibility to apply a random rotation to every duplicate *
proc scatterObject(int $numOfDuplicates,
float $withinMinX,
float $withinMinY,
float $withinMinZ,
float $withinMaxX,
float $withinMaxY,
float $withinMaxZ,
float $rotateMinX,
float $rotateMinY,
float $rotateMinZ,
float $rotateMaxX,
float $rotateMaxY,
float $rotateMaxZ) {
vector $newpos;
vector $newrot;
int $numOfDuplicates = $numOfDuplicates;
int $i = 0;
string $selectedSurface[] = `ls -sl`;
string $newSurface[];
float $x;
float $y;
float $z;
//print("Scatter object(s): " + $selectedSurface + "
");
for($i = 0; $i < $numOfDuplicates;$i++) {
$newpos = `rand <<$withinMinX,$withinMinY,$withinMinZ>> <<$withinMaxX,$withinMaxY,$withinMaxZ>>`;
$newrot = `rand <<$rotateMinX,$rotateMinY,$rotateMinZ>> <<$rotateMaxX,$rotateMaxY,$rotateMaxZ>>`;
$newSurface = `duplicate $selectedSurface`;
print("New duplicates position: " + $newpos.x + ":" + $newpos.y + ":" + $newpos.z + "
");
$x = $newpos.x;
$y = $newpos.y;
$z = $newpos.z;
move -a $x $y $z $newSurface;
$x = $newrot.x;
$y = $newrot.y;
$z = $newrot.z;
rotate $x $y $z $newSurface;
}
}
// e.g. 100 duplicates (of selected object) within a 10 by 10 by 10 cube
// all duplicates are rotated randomly within -45 to +45 on all axis
scatterObject(100, 0, 0, 0, 10, 10, 10, -45, -45, -45, 45, 45, 45);
- animated snapshot puts every duplicated object in it’s on transformation group which is kind of a pain if you want to make animated snapshots of grouped objects (maybe i missing something here - but it didn’t take much to write my own thing)
this quickie will duplicate or instance the selected objects along it’s animation
// animated duplicate/instance script
proc animatedDuplication(int $rangeStart, int $rangeEnd, int $numOfDuplicates, int $duplicateOrInstance) {
int $range_start = $rangeStart;
int $range_end = $rangeEnd;
int $num_of_duplicates = $numOfDuplicates;
int $step_size = ($range_end - $range_start) / $num_of_duplicates;
int $i = 0;
int $temp;
currentTime $range_start; // set to range start
string $selectedObjects[]; // to store selected objects to duplicate or instance
$selectedObjects = `ls -sl`; // store selected objects
select $selectedObjects;
while($i <= $num_of_duplicates) {
$temp = $range_start + ($step_size * $i);
currentTime ($temp);
// seleced the objects to duplicate or instance
select $selectedObjects;
if($duplicateOrInstance == 0)
{
// dulicate
duplicate;
}
else
{
// instance
instance;
}
$i++;
}
}
// e.g. duplicate the current selection 5 times - evenly distributed between frame 1 and 240
animatedDuplication(1, 240, 5, 0);