Wednesday, June 12, 2013

Some Scripting Hints for Facial Rigging

Happy Wednesday,
Here I share a couple of hints and scripts I wrote that helped me considerably speed up facial rigging.
1. Printing a rough expression based on current selection, to aid in connecting facial animator control to some other driver (ex: connecting cluster channels for rivet setup).
//---print expression so can quickly get a control moving something else
dn_lip_anim_loc.tx = dn_lip_anim.tx;
dn_lip_anim_loc.ty = dn_lip_anim.ty; =;
r_dnLip_mid_anim_loc.tx = r_dnLip_mid_anim.tx;
r_dnLip_mid_anim_loc.ty = r_dnLip_mid_anim.ty;
for($arg in `ls -sl`){
string $attr[] = {"tx","ty","tz"};
for($at in $attr){
print($arg+"_loc"+"."+$at+" = "+$arg+"."+$at+";\n");
2. Printing a command to be used for constraining two things based on current selection. By copy and pasting command into a text editor and doing search and replaces constraints can be made quickly between two thing based on naming conventions.
//-- print parent constrain with offset command, would need to edit the parent, child in text editor
global proc na_printPCwithOffsetCmd(){
string $sel[] = `ls -sl`;
string $cmd = "";
for($arg in $sel){
string $parent = $arg;
string $child = ($arg+"_anim_grp");
$cmd+= "parentConstraint -mo "+$parent+" "+$child+";";
print("Run this Command constraint(parent, child) ---\n");

3. Using Python one line string operations in Mel. In this example I wrote I used a python one liner to get the object and attribute from a setAttr type of command.
//--this will run something like eval(`getAttr object.attr`) but it will not error out if an object is missing
//getAttr object.attr --- gives a string of form ex: "setAttr browLeft_anim.visibility 1; setAttr browLeft_anim.translateX 0.1362689445;"
global proc na_evalSetAttr(string $obj, string $attr){
 string $arg = `getAttr ($obj+"."+$attr)`;
 string $all[] = stringToStringArray($arg,";");
 python("import re");

 for($cmd in $all){
 string $obj = "";
 $obj = python("'setAttr')+'(.*)'+re.escape(' '),'"+$cmd+"'.strip() ).group(1)");//ex: browLeft_anim.translateX
 if(`objExists $obj`){eval($cmd+";");}else{print($obj+" :NOT FOUND--Skipping!!!\n");}
print("Run:-- na_evalSetAttr(poses transform string, and its pose attribute string ) --ex:\n na_evalSetAttr(\"poses\",\"smile\")\n");

Hope this was helpful,

Inspired by John La Rooy's find string between two substrings online python tutorial examples