MEL Scripting:

arrows.GIF

List of Mel commands:
Help->Maya Scripting Reference->MEL Command Reference

Open the Window->General Editors->Script Editor...
Paste your script in the lower MEL area
Use Command->Execute from the editor


// comments a line
always end a command line with a ;   semi colon



Select with a wild card
select -r "nurbsPlane\*";



select 10 nurbsplanes
int $i;
for ($i = 1; $i <= 10; $i++) {        // The variable $i is equal to between 1 and 10
select -tgl ("nurbsPlane"+$i);}


Randomize a poly sphere
Use Display->Heads Up Display->Poly Count to see how many vertices are on your sphere
int $i;
for ($i = 1; $i <= 381; $i++) {
select -r pSphere1.vtx[$i] ;
move -r (rand(-.1,.1)) (rand(-.1,.1)) (rand(-.1,.1)) ;}



Rock Maker
polyCube -w 1 -h 1 -d 1 -sx 1 -sy 1 -sz 1 -ax 0 1 0 -cuv 4 -ch 1;
string $sel[] = `ls -sl`;
for($i=0;$i<size($sel);$i++) {
print ($sel[$i]+"\n");
polySmooth  -mth 0 -sdt 2 -ovb 1 -ofb 3 -ofc 0 -ost 1 -ocr 0 -dv 1 -bnr 1 -c 1 -kb 1 -ksb 1 -khe 0 -kt 1 -kmb 1 -suv 1 -peh 0 -sl 1 -dpe 1 -ps 0.1 -ro 1 -ch 1 ($sel[$i]);
polySmooth  -mth 0 -sdt 2 -ovb 1 -ofb 3 -ofc 0 -ost 1 -ocr 0 -dv 1 -bnr 1 -c 1 -kb 1 -ksb 1 -khe 0 -kt 1 -kmb 1 -suv 1 -peh 0 -sl 1 -dpe 1 -ps 0.1 -ro 1 -ch 1 ($sel[$i]);
polySmooth  -mth 0 -sdt 2 -ovb 1 -ofb 3 -ofc 0 -ost 1 -ocr 0 -dv 1 -bnr 1 -c 1 -kb 1 -ksb 1 -khe 0 -kt 1 -kmb 1 -suv 1 -peh 0 -sl 1 -dpe 1 -ps 0.1 -ro 1 -ch 1 ($sel[$i]);
polySmooth  -mth 0 -sdt 2 -ovb 1 -ofb 3 -ofc 0 -ost 1 -ocr 0 -dv 1 -bnr 1 -c 1 -kb 1 -ksb 1 -khe 0 -kt 1 -kmb 1 -suv 1 -peh 0 -sl 1 -dpe 1 -ps 0.1 -ro 1 -ch 1 ($sel[$i]);
polySmooth  -mth 0 -sdt 2 -ovb 1 -ofb 3 -ofc 0 -ost 1 -ocr 0 -dv 1 -bnr 1 -c 1 -kb 1 -ksb 1 -khe 0 -kt 1 -kmb 1 -suv 1 -peh 0 -sl 1 -dpe 1 -ps 0.1 -ro 1 -ch 1 ($sel[$i]);
polySmooth  -mth 0 -sdt 2 -ovb 1 -ofb 3 -ofc 0 -ost 1 -ocr 0 -dv 1 -bnr 1 -c 1 -kb 1 -ksb 1 -khe 0 -kt 1 -kmb 1 -suv 1 -peh 0 -sl 1 -dpe 1 -ps 0.1 -ro 1 -ch 1 ($sel[$i]);
polySmooth  -mth 0 -sdt 2 -ovb 1 -ofb 3 -ofc 0 -ost 1 -ocr 0 -dv 1 -bnr 1 -c 1 -kb 1 -ksb 1 -khe 0 -kt 1 -kmb 1 -suv 1 -peh 0 -sl 1 -dpe 1 -ps 0.1 -ro 1 -ch 1 ($sel[$i]);
setAttr ($sel[$i]+".scaleZ") (rand(50,300));
setAttr ($sel[$i]+".scaleX") (rand(50,300));
setAttr ($sel[$i]+".scaleY") (rand(50,300));
softSelect -e -softSelectEnabled true;
softSelect -e -softSelectDistance 100;
select -r ($sel[$i]+".vtx[348]") ;
move -r -1.479345 -12.173582 -7.263036 ;
select -r ($sel[$i]+".vtx[302]") ;
move -r -8.425104 8.101759 4.151861 ;
select -cl  ;
};


Print a list from 1 to 10 with a period and line return
int $i;
for ($i = 1; $i <= 10; $i++) {
print($i+".\n");}



string $object = "cake";
print ($object + ".tx");       //Syntax to string words together for a  command


Select a bunch of texture maps, turn off Quadratic
string $sel[] = `ls -sl`;
for($i=0;$i<size($sel);$i++) {
print ($sel[$i]+"\n");
setAttr ($sel[$i]+".filterType") 0;
};


Select a sphere with animation, copy it 10 times, each copy moves 3 units in x
int $i;
for ($i = 1; $i <= 10; $i++) {        // The variable $i is equal to a range between 1 and 10
select -r ("nurbsSphere"+$i);
duplicate -rr -un;
move -r 3 0 0 ;
}


Rename selected objects with a numerical sequence starting from 1
$prefix="pp";
string $sel[] = `ls -sl`;
for($i=0;$i<size($sel);$i++) {
print ($sel[$i]+"\n");
rename ($sel[$i]) ($prefix+($i+1));
};



A script to advance 1 frame up to 150, Select an animated poly sphere and copy it
int $f = 0;
while ($f <= 150) {
playButtonStepForward;
select -r pSphere1;
duplicate -rr;
$f += 1;
};