Labels

Sunday, 30 October 2011

Some work

While I've been researching for my proposal, I've been trying to brush up on my practical skills. I recently got a book titled "MEL Scripting a Character Rig in Maya" by Chris Maraffi.



As I'm learning a brand new skill, I've only been following the examples in the book. The code I've written is the code found within the first chapters, but I have annotated it with comments to help me understand it better. I've also written a supplementary "cheat sheet" of commands and more general advice. Here's what I've done so far:


/*
Defining, Querying and Editing Variables
*/
//defined variables
int $num = 7;
float $dec = 3.267;
string $name = "mySphere";
int $nums[];
float $decs[5] = {7.23,1.0,20.7,0.567,12.0};
string $names[] = {"One", "Two", "Three"};
sphere -n $name -p 0 0 0 -ax 0 1 0 -ssw 0 -esw 360 -r 1 -d 3
-s 8 -nsp 4 -ch 1;
string $names[] = `sphere -n $name -p 0 0 0 -ax 0 1 0 -ssw 0
-esw 360 -r 1 -d 3 -s 8 -nsp 4 -ch 1`;
//print nodes
print $names;
//defining queryable variables
int $spans = `sphere -q -nsp $names[1]`;
int $radius = `sphere -q -r $names[1]`;
//query and print number of spans in sphere and the radius through the
//command node
print ("Number of spans: " + $spans + "\n");
print ("Radius: " + $radius + "\n");
//looks at sphere command and edits the radius to match the number of spans
sphere -e -r $spans $names[1];


/*
Defining the Selected Node and making it a variable
*/
string $selNodes[] = `ls -sl`;
print $selNodes;
/*
Selecting multiple nodes
*/
string $names[] = `sphere -n $name -p 0 0 0 -ax 0 1 0 -ssw 0
-esw 360 -r 1 -d 3 -s 8 -nsp 4 -ch 1`;
select -tgl $names[1];
string $selNodes[] = `ls -sl`;
print $selNodes;
/*
Change Get Value of X scale and set it as Y translate
*/
string $names[] = `sphere -n $name -p 0 0 0 -ax 0 1 0 -ssw 0
-esw 360 -r 1 -d 3 -s 8 -nsp 4 -ch 1`;
getAttr ($names[0] + ".sx");
setAttr ($names[0] + ".ty") 5;
/*
Catch sections attribute and set spans attirbute to match
*/
string $names[] = `sphere -n $name -p 0 0 0 -ax 0 1 0 -ssw 0
-esw 360 -r 1 -d 3 -s 8 -nsp 4 -ch 1`;
int $sections = `getAttr ($names[1] + ".s")`;
setAttr ($names[1] + ".nsp") $sections;
//Creates a new attribute that has a long name, short name and nice name, with a floating value
//that is keyable, minumum value of -10, maximum value of 10, default value of 0, readable and writeable
//affecting the tranform node of $names, i.e. Sphere.
addAttr -ln "myAttr" -sn "ma" -nn "My Attribute" -at "float"
-min -10 -max 10 -dv 0 -k 1 -r 1 -w 1 $names[0];

Cheat Sheet:


List of Useful MELScript Commands:
` = catches a return value
select -cl; = clears selection
select -r; = select node
select -tgl; = toggles a node
listAttr; = list all attributes on a node
getAttr; = query or get information on an attribute
setAttr; = edit or set information on an attribute
".sx" = define attribute (note flag here is short name for scale x)
EXAMPLE
getAttr ($names[0] + ".sx");
-k/-keyable =
EXAMPLE
//lists all keyables attributes on the transform node of the object
listAttr -k $names[0]
help = synopsis of the command
whatIs = tells if command is a procedure found in the MELscript folder when loaded
float = decimal number, may be also referred to as length/double
int = integer
string = text
vector/matrix = groups of numbers
"on"|"off" = "true"|"false". 1|0
rename = gives object new name
"/n" = new line
/* |
Hello World |= Block comment
*/ |
//Hello World = single line comment
[define type of flag] [variable name] = [result]
EXAMPLE:
int $num = 7;
OR
string $selNodes[] =  `ls -sl`;
xform = consolidate multiple types of transforms with one command

No comments:

Post a Comment