/* */

Saturday, 10 September 2011

Match Pivot Script

Quick script i've put together that'll match the worldspace pivot point of one object to the other. Very simple just useful for modelling and rigigng purposes:


//Match Pivot by jim dunford 10/09/2011

string $object[] = `ls -sl`;

int $arraySize = `size $object`;
if ($arraySize < 2)
print "only one object selected";
else

{
vector $e = `xform -q -rp -ws $object[0]`;
setAttr($object[1]+ ".translateX") ($e.x);
setAttr($object[1]+ ".translateY") ($e.y);
setAttr($object[1]+ ".translateZ") ($e.z);
print "great success!";
}



<< 01 02 03 04 05 06 07 08 09 10 >>

Thursday, 14 October 2010

Operator precedence

Taken from cgSultra, useful page I found detailing key fundamental concepts of MEL scripting. the image below gives clear representation to the order of precedene an operator takes:


The following shows order of operator precedence in MEL. Operator in same row has equal precedence. Left most operator is evaluated first, if a statement has more then one operators of equal precedence.





Thursday, 6 May 2010

Gradient Control

Useful link I found regarding working with the "Gradient Control" command which creates a ramp widget. This I have seen in a rigging showreel used to good effect to control the deformation of a characters torso/limbs and could be useful for the usbman rig.

Thursday, 15 April 2010

MEL Wiki

Web resources I have found that provide information about MEL commands.

Autodesk - Trusty ol'faithful
Wiki - Pertinent questions down the right, put in laymans terms so I can understand it
caad
Twiki
Tiddlyspot - Visual guide of UI Controls, commands included.
Learning Maya - More than just a MEL resource
Cg Sutra - Useful introductory tutorials on using MEL

Tuesday, 23 February 2010

Creating a UI with formLayout

Form layout offers the programer a bit more control when designing Ui layout. Each control ie Text Fields, Buttons, Input Text are positioned in relation to each other by stipulating in the code which edge you want to join with the other.

Similar to a jigsaw puzzle - you can't float a piece on a table, it has to be connected to the surrounding pieces.

Good Flags to Use:

formLayout myForm;

This will create a form layout called "myForm", naming is very important in order to refer to it later.

formLayout -e

The -e field allows you to edit the command, can also use a -q to query it. The commands keyed under formLayout -e will determine the positioning of its components. This should then be closed off by ;

-attachForm (-af)

// Attaches the component to the form. This should be followed by two strings (the name of the component and the edge you wish to attach) and an integer (the offset from that edge). Typically should look like:
-attachForm component name 0

-attachControl (-ac)

//Attaches control to another control. Requires four arguments string, string, integer, string. Typically should look like:

-attachControl control top 0 second controler

All these commands and fields are listed in the Maya help guide which also provides an example of the correct syntax.

Procedures

A procedure is a group of MEL commands that are activated by thei name.

Useful MEL Commands - Loop Statements

Loops (also known as iterations) allow you to repeatedly execute statements as long as a statement is true.


Different Types of Loops
1. While-loops, work like an if statement, except it will continue to evaluate until the condition is satisfied/exceeded.


The parameters are stipulated in the scrip, so for instance you could tell it to repeat a process (such as create a poly primitive) 20 times. When that process reaches 20 it stops.

MEL Commands

To comment a line out - usually a good idea to describe what the code is doing eg:

//This line will (purpose of the code)

Any line preceded by // will not be evaluated when run, and is a good way of stating the scripts funtion clearly, for debugging purposes.

Always terminate (end) a line with an ;

Variables and Data Types
Variables act as dynamic containers that acquire and store information according to the command assigned to it. Always preceded by a $ sign. Variables yeild different data types, eg (MEL equivalent in brackets)

1. Integers (int) - whole numbers
2. Floats (float)- Numbers with decimal places
3. Vectors (vector) - values derived from three numbers - such as position x8, y9, z4
4. Strings (string) - a collection of characters (words and numbers) eg psphere1
5. Arrays ([]) - Variables with more than 1 object are given a number (eg [1]) and can be reffered to. As seen in Nodes such as MultiplyDivide Node where more than one equation can be attached to the same node. I recall being stuck for days on a tutorial because it didn't have enough array slots, then I realise the only way of doing this was to add an array using MEL.

Variables allow for dynamic content, so their contnt will update accordingley.

//To write a variable:
$MyVariable

//You can give a variable any name it wants but it cannot start with a number eg:
$10Variable

*/This would be incorrect, the variable however can contain numbers after the first letter eg: */
$Variable10

Precede the variable with the data type eg:

int $myVariable - Variable can only contain whole numbers
string &myVariable - Variable can only contain characters (name of object) and must be encapsulated by "" eg "psphere1"
float $myVariable - Variable can have any number (including decimal places)
vector $myVariable - Variable contains a value that requires 3 numbers to delineate it eg colour (RGB) or position (xyz). Vector variables are storred within <<>> brackets. eg:
<<12, 87.59, 43>> Maya will automatically turn these values into float values eg:
<<12.0, 87.59, 43.0>>


Anything within `` marks (for instancel: `modelpanel -q -camera ($whichPanel)`;
means it will be evaluated.



Condition Syntax:
(other wise known as "if" or "else" statements)

< : less than
> : greater than
== equal to
!= not equal to
>= greater or equal to
<= less or

Tuesday, 16 February 2010

Useful MEL Commands - ik Spring Solver

Following useful in the rigging process, explanation underneath:

ikSpringSolver;
Will add the spring IK solver to the list of IK handles you can use - useful for limbs with more than two segments, ie insect legs