Tuesday, 10 January 2012

Mel: Parenting shape nodes to new parents (ie polyMesh to Joint)

Was asked about combining a polySphere/nurbsSphere to a joint, so selecting the sphere still selects the joint.

Its fairly simple actually, its the same way as you would combine two nurbs curves under one transform node (to get more complex/detailed control objects).

string $parent="joint1"; string $shape="pSphereShape1"; parent -add -shape $shape $parent;
As simple as!

Saturday, 7 January 2012

Mel/Python: Splitting a string by a string (tokenize vs .split)

I know its only a small post and I don't go into detail, more of an outline... it really did bug me was how there are no expressions for tokenize.
I spent a bit of time trying to split a string (ie "L_clavicle_bind_jnt") by with the string "_bind_".
What I found with using tokenize was that it will split the string by the characters instead of the entire string, which to me, was a pain in the backside as I wanted {"L_clavicle","jnt"} but what i'd get with tokenize was {"L,"clav","cle","j","t"}. Now this wouldn't do, and I could find any out of the box way of doing this (I wanted to replace "_bind_" with "_IK_", etc to search), so I ended up turning to python (yet again).
It couldn't be simplier.
"L_clavicle_bind_jnt".split("_bind_")
Which translated as -
python("'"+$child+"'.split('_"+$namespace+"_')") ;
Thinking about it now, im sure there is a command to do this in mel, I just cant find it...

Thursday, 5 January 2012

Using Python list comprehension

Just a quick example of how I use list comprehension to search for matching entries in two lists (of course there's x amount of ways to do this, and results will vary depending on usage).

# two lists with some matching entries a=['jon','mary','frank'] b=['lewis','frank','jon','clive','betty','toni','jim'] #typical method using for loop with if/in statement results=[] for i in a: if i in b: results.append(i) print results # with list comprehension results=[x for x in a if x in b] print results

Adding notes to nodes in Maya through mel

Its fairly straightforward to add notes to a node in Maya (under Attribute Editor, add text to under Notes section), but through mel there's one more step you need to go through before you can.

Simply put, the node needs a "notes" (or s/n "nts") attribute first, then its plain sailing (manually writing a note creates the attr, which then stores the string - or so im assuming, looks like that's handled through a scriptJob)
So to add a note to a node, first check whether it already has an attribute called "notes", create one if not, then write something.
string $node[]=`polyCube` ; if(!`attributeQuery -node $node[0] -ex "notes"`) addAttr -ln "notes" -sn "nts" -dt "string" $node[0] ; setAttr -type "string" ($node[0]+".notes") "This node now has a Note. You can store various bits of information here." ; (The note on this script example is on the transform node of the polyCube object ($node[0]) as $node[1] would be the shape object)

Wednesday, 4 January 2012

Iconicles VFX Showreel




My work includes;
All Character/Prop Rigs, as well as - Animation, Dynamics, Animation Tools and Pipeline Development/Tools.


Still sorting current showreel, will be up asap.

Selecting animated objects

Quick little script for selecting any (dag) objects with animation on.
string $allObjects[]=`ls` ; select -cl; for($i=0;$i<`size($allObjects)`;$i++) if(`keyframe -q -keyframeCount $allObjects[$i]` != 0) select -tgl $allObjects[$i] ;
I was already aware that mel doesn't need curly brackets "{}" following if statements or for loops (will only execute the next line of code), it seems that it doesn't need them even if your incorporating another statement or loop :) such as the above code shows...

Tuesday, 3 January 2012

Toggle lighting script

simple script to toggle the lighting between "default" and "use all lighting" on the current panel.
string $currentPanel=`getPanel -withFocus` ; string $mode="default" ; if(`getPanel -to $currentPanel`=="modelPanel") if(`modelEditor -q -dl $currentPanel`=="default") $mode="all" ; modelEditor -edit -dl $mode $currentPanel ;