// llMirrorGeometry // ////////////////////////// // // Maya script file // ////////////////////////// // // Author : Lluís Llobera // (lluisllobera@hotmail.com) // // Creation date : 19/VII/2003 // UPDATE 1.1 : 11/VIII/2003 // // Main procedure : type "llMirrorGeometry" in the Command Line or Script Editor // ////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////// // // This script mirrors geometry along any ortographic plane. It includes a "replacing" option. // // It is most useful when creating "tweeen" controllers for a rig. // // UPDATE 1.1 // // Now the scripts works correctly in Maya 5.0. I had not checked it yet, and it seems that // there was an extra step that I overlooked and that needed attending to from Maya 4 to Maya 5. // // // Enjoy!! // //////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////// // llReturnLonelyName // ////////////////////////////////// // // 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 llReturnLonelyName (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 llReturnLonelyName ////////////////////////////////// // llMakeRename // ////////////////////////////////// // // This is a little proc that I use multiple times in different scripts... // // It just renames the selected node to $NAME // ///////////////////////////////// global proc llMakeRename (string $NAME) { string $SELECTED[] = `ls -sl` ; rename $SELECTED[0] $NAME ; } ; // global proc llMakeRename ////////////////////////////////// // llMakeConstraint // ////////////////////////////////// // // This is a little proc that I use multiple times in different scripts... // // It constrains $TARGET to $PARENT, in point, orient or scale // ///////////////////////////////// global proc llMakeConstraint (int $POINT , int $ORIENT , int $SCALE , string $PARENT , string $TARGET) { select -r $PARENT $TARGET ; if ($POINT) pointConstraint ; if ($ORIENT) orientConstraint ; if ($SCALE) scaleConstraint ; } ; // global proc llMakePointOrientConstraint ////////////////////////////////// // llSetSubstituteString // ////////////////////////////////// // // This is a little proc that I use multiple times in different scripts... // // It goes through all the elements of a set and renames them, // substituting $TEXT1 for $TEXT2 if $TEXT1 is found in the elements' name // ///////////////////////////////// global proc llSetSubstituteString (string $SET , string $TEXT1 , string $TEXT2) { // variable definition int $setSize = eval ("size `sets -q " + $SET + "`") ; string $ELEMENT ; string $NEWCHILD ; int $I ; // proc start for ($I = 0 ; $I <= $setSize - 1 ; $I++ ) { string $LIST[] ; $LIST = eval ("sets -q " + $SET) ; $NEWCHILD = `llReturnLonelyName $LIST[$I]` ; $NEWCHILD = `substitute $TEXT1 $NEWCHILD $TEXT2` ; select -r $LIST[$I] ; llMakeRename $NEWCHILD ; } ; } ; // global proc llMirrorTransformRenameSet ////////////////////////////////// // llMirrorTransformGo // ////////////////////////////////// // // This proc actually creates the "mirrored" transform // ///////////////////////////////// global proc llMirrorTransformGo ( string $ELEMENT , int $AXIS , string $TEXT1 , string $TEXT2) { // variables definition string $G1[] ; string $G2[] ; string $NEWELEMENT = `substitute $TEXT1 $ELEMENT $TEXT2` ; string $NEWNAME = $NEWELEMENT ; if ($ELEMENT == $NEWELEMENT) $NEWNAME = ($ELEMENT + "_A") ; string $CHILD ; string $NEWCHILD ; // proc start // make duplicates and rename them select -r $ELEMENT ; duplicate -rr ; llMakeRename $NEWNAME ; duplicate -rr ; llMakeRename ($NEWNAME + "B") ; // delete children of $NEWNAME select -r $NEWNAME ; select -hi ; select -tgl $NEWNAME ; delete ; // create constraints llMakeConstraint (1 , 1 , 0 , ($NEWNAME + "B") , $NEWNAME ) ; // group $NEWNAME+B createNode transform -n ("g" + $NEWNAME + "B") ; parent ($NEWNAME + "B") ("g" + $NEWNAME + "B") ; // scale to -1 if ($AXIS == 1) setAttr ("g" + $NEWNAME + "B.scale") 1 1 -1 ; else if ($AXIS == 2) setAttr ("g" + $NEWNAME + "B.scale") -1 1 1 ; else setAttr ("g" + $NEWNAME + "B.scale") 1 -1 1 ; // parent children of $NEWNAME+B to $NEWNAME select -r ($NEWNAME + "B") ; select -r `listRelatives -c -f` ; select -tgl $NEWNAME ; parent ; // freeze transformations on reparented children FreezeTransformations ; // creates a set with the down hierarchy select -hi ; string $llMirrorTransformSet = `sets` ; // renames set elements if necessary llSetSubstituteString ($llMirrorTransformSet , $TEXT1 , $TEXT2) ; // deletes set delete $llMirrorTransformSet ; // deletes constraints delete ($NEWNAME + "_pointConstraint1") ($NEWNAME + "_orientConstraint1") ; // delete g+$NEWNAME+B delete ("g" + $NEWNAME + "B") ; } ; // global proc llMirrorTransformGo ////////////////////////////////// // llMirrorTransformParse // ////////////////////////////////// // // This proc takes the information from the window // and calls on llMirrorTransformGo a number of times // ///////////////////////////////// global proc llMirrorTransformParse () { // variables from window int $AXIS = `radioButtonGrp -q -sl llMTWAcrossRadioButton` ; string $TEXT1 = `textFieldGrp -q -tx llMTWText1` ; string $TEXT2 = `textFieldGrp -q -tx llMTWText2` ; // variables for the proc string $LIST[] = `ls -sl -type transform` ; // proc start if (`size $LIST` == 0) error ("select at least one transform node") ; else for ($ELEMENT in $LIST) llMirrorTransformGo ($ELEMENT , $AXIS , $TEXT1 , $TEXT2 ) ; } ; // global proc llMirrorTransformParse ////////////////////////////////// // llMirrorTransform // ////////////////////////////////// // // MAIN PROC // // This proc creates the main window. // ///////////////////////////////// global proc llMirrorTransform () { if (`window -ex llMirrorTransformWindow`) deleteUI llMirrorTransformWindow ; window -wh 465 165 -s 0 -minimizeButton 0 -maximizeButton 0 -title "llMirrorTransform v1.1" llMirrorTransformWindow ; columnLayout -adj 1 llMTWStructure ; text "\n llMirrorTransform v1.1\n" ; radioButtonGrp -numberOfRadioButtons 3 -l "Mirror Across" -sl 2 -la3 "XY" "YZ" "XZ" llMTWAcrossRadioButton ; separator -style "none" -h 5 ; textFieldGrp -l "Substitute this string" -tx "" llMTWText1 ; textFieldGrp -l "With this string" -tx "" llMTWText2 ; separator -style "none" -h 10 ; columnLayout -cat "both" 175 -adj 1 llMTWButtonLayout ; button -l "GO !" -c "llMirrorTransformParse" llMTWButtonGo ; showWindow llMirrorTransformWindow ; window -e -wh 465 165 llMirrorTransformWindow ; } ; // global proc llMirrorTransform //////////////////////////////////////////////////////////////////////////////////////////////////// // // EoS llMirrorTransform // ////////////////////////////////////////////////////////////////////////////////////////////////////