// llOrientJoint // ////////////////////////// // // Maya script file // ////////////////////////// // // Author : Lluís Llobera // (lluisllobera@hotmail.com) // // Creation date : 17/I/2003 // UPDATE 1.1 : 23/I/2003 // UPDATE 1.2 : 15/II/2003 // UPDATE 1.5 : 23/X/2003 // // Main procedure : type "llOrientJoint" in the Command Line or Script Editor // ////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////// // // Based on Jason Schiefler's, this script orients the selected parent joints correctly in the // specified axis. // // UPDATE 1.1 // Fixed a bug that used to happen when multiple objects were named the same but were placed in // different hierarchies. // // UPDATE 1.2 // Corrected the script to work as it should when the selected joint was parent to two other // joints. // Also, now the script finishes with the selection of the joints parented to the recently // oriented ones. // // UPDATE 1.5 // Changed the core of the orient joint procedure -- now it works better :-) // // // Enjoy!! // //////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////// // returnLonelyName // ////////////////////////////////// // // This is a little proc that I use multiple times in different scripts... // It just returns the "lonely name" of the selected object in scene, raw, without // "|" or hierarchy names whatsoever. // ///////////////////////////////// global proc string returnLonelyName (string $NOM) { int $MIDANOM = `size $NOM` ; int $SEPARATOR = 0 ; for ($I = 1 ; $I < $MIDANOM ; $I++) { string $CHAR = `substring $NOM $I $I` ; if ($CHAR == "|") $SEPARATOR = $I ; } ; // for return `substring $NOM ($SEPARATOR + 1) $MIDANOM` ; } ; // global proc string returnLonelyName ////////////////////////////////// // llOJMakeOrientJoint // ////////////////////////////////// // // Orients the selected joints // // // <-- llOrientJoint // ///////////////////////////////// global proc llOJMakeOrientJoint () { // // variables definition // // selected joints string $JNames[] = `ls -sl -type joint` ; // axis variables string $AimAxis = `radioCollection -q -sl llOJColeAimAxis` ; string $UpAxis = `radioCollection -q -sl llOJColeUpAxis` ; int $inverseAim = `checkBox -q -v llOJCheckBoxInverseAim` ; int $inverseUp = `checkBox -q -v llOJCheckBoxInverseUp` ; // adds "I" to the $inverseAim if the checkBox "inverse Aim" is checked on if ($inverseAim == 1) $AimAxis = ($AimAxis + "I") ; // adds "I" to the $inverseUp if the checkBox "inverse Up" is checked on if ($inverseUp == 1) $UpAxis = ($UpAxis + "I") ; // creates a string 100 / 010 / 001 for the AimAxis and UpAxis switch ($AimAxis) { case "aimAxisX" : $AimAxis = " 1 0 0 " ; break ; case "aimAxisY" : $AimAxis = " 0 1 0 " ; break; case "aimAxisZ" : $AimAxis = " 0 0 1 " ; break ; case "aimAxisXI" : $AimAxis = " -1 0 0 " ; break ; case "aimAxisYI" : $AimAxis = " 0 -1 0 " ; break; case "aimAxisZI" : $AimAxis = " 0 0 -1 " ; break ; } ; // switch ($AimAxis) switch ($UpAxis) { case "upAxisX" : $UpAxis = " 1 0 0 " ; break ; case "upAxisY" : $UpAxis = " 0 1 0 " ; break; case "upAxisZ" : $UpAxis = " 0 0 1 " ; break ; case "upAxisXI" : $UpAxis = " -1 0 0 " ; break ; case "upAxisYI" : $UpAxis = " 0 -1 0 " ; break; case "upAxisZI" : $UpAxis = " 0 0 -1 " ; break ; } ; // switch ($UpAxis) // variables for temporal nodes string $temporalGroup ; string $temporalTransform ; // variable to decide whether the script can go on or not int $CONTINUE ; // // proc start // for ($JName in $JNames) { // reset $CONTINUE $CONTINUE = 0 ; // select children of $JName string $jointUnder[] = `listRelatives -children -f $JName` ; // examine children of $JName and see if there's any joint between them for ($ELEMENT in $jointUnder) if (`nodeType $ELEMENT` == "joint") $CONTINUE = 1 ; if ($CONTINUE) { // groups $jointUnder under a temporal group string $temporalGroup = `createNode transform -n "temporalGroup"` ; parent $jointUnder $temporalGroup ; // gets new full path name for $jointUnder $jointUnder = `listRelatives -children -f $temporalGroup` ; // sets joint orientation to 0 setAttr ($JName + ".jo") 0 0 0 ; // creates the Aim Constrain between the underJoint and the selectedJoint string $temporalConstrain[] = eval ("aimConstraint -w 1 -aimVector " + $AimAxis + " -upVector " + $UpAxis + " -worldUpType scene " + $jointUnder[0] + " " + $JName) ; // deletes the Aim Constrain delete $temporalConstrain ; // copies the "r" to the "jo" of $JName setAttr ($JName + ".jox") (`getAttr ($JName + ".rx")`) ; setAttr ($JName + ".joy") (`getAttr ($JName + ".ry")`) ; setAttr ($JName + ".joz") (`getAttr ($JName + ".rz")`) ; // sets the "r" of $JName to 0 setAttr ($JName + ".r") 0 0 0 ; // parents back the former children to $JName parent (`listRelatives -children -f $temporalGroup`) $JName ; // deletes remaining extra nodes delete $temporalGroup ; } // if ($CONTINUE) else error ("selected joint is not parent of other joints") ; } ; // for ($JName in $JNames) // select children of selected joints if ($CONTINUE) select -r `listRelatives -children -f $JNames` ; } ; // global proc llOJMakeOrientJoint ////////////////////////////////// // llOrientJoint // ////////////////////////////////// // // MAIN PROC // // // --> llOJMakeOrientJoint // ///////////////////////////////// global proc llOrientJoint () { if (`window -ex llOrientJointWindow` == 1) deleteUI llOrientJointWindow ; window -wh 300 210 -minimizeButton 0 -maximizeButton 0 -s 0 -title "llOrientJoint v1.5" llOrientJointWindow ; columnLayout -co "left" 10 ; separator -style "none" -h 7 ; text "Aim Axis :" ; separator -style "none" -h 7 ; rowColumnLayout -nc 3 -cat 1 "left" 30 -cat 2 "left" 15 ; radioCollection llOJColeAimAxis ; radioButton -l "X" aimAxisX; radioButton -sl -l "Y" aimAxisY; radioButton -l "Z" aimAxisZ; setParent .. ; separator -style "none" -h 7 ; text "Up Axis :" ; separator -style "none" -h 7 ; rowColumnLayout -nc 3 -cat 1 "left" 30 -cat 2 "left" 15 ; radioCollection llOJColeUpAxis ; radioButton -l "X" upAxisX; radioButton -l "Y" upAxisY; radioButton -sl -l "Z" upAxisZ; setParent .. ; separator -style "none" -h 12 ; columnLayout -cat "left" 90 -rs 3 ; checkBox -l "inverse Aim" llOJCheckBoxInverseAim ; checkBox -l "inverse Up" llOJCheckBoxInverseUp ; setParent .. ; separator -style "none" -h 12 ; columnLayout -cat "left" 70 ; button -l "GO !" -c "llOJMakeOrientJoint" -w 120 ; showWindow llOrientJointWindow ; } ; // global proc llOrientJoint //////////////////////////////////////////////////////////////////////////////////////////////////// // // EoS llOrientJoint // ////////////////////////////////////////////////////////////////////////////////////////////////////