Helpful mel commands
more info can be found in the maya "mel command reference"
size
gets the size of a variable, or the number of individual items within an array
syntax:
for(i=0;$i<size($tabu);$i++){} //setting a loop to run through all items
float $number = `size($tabu)`; //get number of items in an array and storing the result in $number
stringArrayCount
find the number of times a given item is found in an array - usefull for determining if something had been flagged or has already been operated on
syntax:
int $tabuCount = stringArrayCount(200, $tabu); //searches the $tabu array for the number "200" - returns the number of times 200 is present in $tabu
pointPosition
gives the location in space (XYZ) of any particle object (i.e. an object with no size - particles, locators, CVs, vertex)
syntax:
float $pos[] = `pointPosition ($particles[0]+".pt["+$i+"]")`; //loads XYZ of a given particle (in this case, a complex name put together from different variables
float $pos[] = `pointPosition "locator1"`; // loads XYZ of locator1 into $pos
tokenize
splits a string into parts, seperated by a given "seperator", in this case "." in order to split "particle1.pt[907]" into "particle1" and "pt[907]"
syntax:
string $buffer[]; // you must create a buffer to load the split version into
tokenize $choice "." $buffer; //this splits the string $choice and loads the results into the array $buffer
match
pulls out a given character set from a string - mostly usefull for pulling numbers out of a complex string - returns whatever is "matched"
syntax:
$pos = `match "[0-9]+" $buffer[1]`; //here we are matching anything that is between 0-9, and returning all matches - effectively pulling out all numbers from $buffer[1] and placeing them into $pos
ls
used for listing out whatever is selected - we can select as many things as we like and then load their names into an array variable of our choosing - the -sl flag tells the list command to give back whatever is selected - the -fl flag tells it to list each out individually rather than trying to shorten the list (i.e. list object.vtx[1] and object.vtx[2] seperately, rather than using the shorthand object.vtx[1:2])
syntax:
string $queue[] = `ls -sl -fl`; //loads selection into $queue
eval
used to execute a string as a command - this allows you to incrementally build a command string (to create particles, or curves by individually placing CVs)
syntax:
string $command = "curve -d 3 "; //establish command string
$command = ($command +" -p "+$p1[0]+" "+$p1[1]+" "+$p1[2]); //add to command
string $result[] = `eval($command)`; //run command and capture name of the result