////////////////////////// // // Maya script file // ////////////////////////// // // Author : Lluís Llobera // (lluisllobera@hotmail.com) // // Creation date : 13/II/2005 // // Main procedure : type "llIncrementAttributes" in the Command Line or Script Editor // ////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////// // // This script will create a window to allow the user to quickly add, substract, // multiply or divide the specified attribute by the specified value. // // // Enjoy!! // //////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////// // llIAWMakeIncrement // ////////////////////////////////// // // Sets the correct value to the specified $ELEMENT.$ATTRIBUTE // // --> llIAWExecute // ///////////////////////////////// global proc llIAWMakeIncrement (string $ELEMENT , string $ATTRIBUTE , int $OPERATION , float $INCREMENT) { string $WHOLE = ($ELEMENT + "." + $ATTRIBUTE) ; float $CURRENT_VALUE = `getAttr $WHOLE` ; float $NEW_VALUE ; switch ($OPERATION) { case 1 : // add $NEW_VALUE = $CURRENT_VALUE + $INCREMENT ; break ; case 2 : // subtract $NEW_VALUE = $CURRENT_VALUE - $INCREMENT ; break ; case 3 : // multiply $NEW_VALUE = $CURRENT_VALUE * $INCREMENT ; break ; case 1 : // divide $NEW_VALUE = $CURRENT_VALUE / $INCREMENT ; break ; } ; // switch $OPERATION setAttr $WHOLE $NEW_VALUE ; } ; // global proc llIAWMakeIncrement ////////////////////////////////// // llIAWExecute // ////////////////////////////////// // // After controlling a lot of possible misshappenings, // gets the current type of the attribute and // calls on to llIAWMakeIncrement // // <-- llIncrementAttributes // --> llIAWMakeIncrement // ///////////////////////////////// global proc llIAWExecute () { string $SELECTION[] = `ls -sl` ; string $ATTRIBUTE = `textFieldGrp -q -tx llIAWAttributeName` ; float $INCREMENT = `floatFieldGrp -q -v1 llIAWIncrement` ; int $OPERATION = `radioButtonGrp -q -sl llIAWOperation` ; string $OPERATOR ; int $ERRORS = 0 ; if (`size $SELECTION` == 0) error ("select some nodes from the scene") ; else if (`size $ATTRIBUTE` == 0) error ("specify an attribute to increment") ; else if (($OPERATION == 4) && ($INCREMENT == 0)) error ("cannot divide by 0") ; else for ($ELEMENT in $SELECTION) { string $WHOLE = $ELEMENT + "." + $ATTRIBUTE ; if (`objExists $WHOLE`) { if (`getAttr -l $WHOLE`) $ERRORS = $ERRORS + 1 ; else { string $CURRENT_TYPE = `getAttr -type $WHOLE` ; switch ($CURRENT_TYPE) { case "double" : case "doubleAngle" : case "doubleLinear" : case "long" : llIAWMakeIncrement ($ELEMENT , $ATTRIBUTE , $OPERATION , $INCREMENT) ; break ; case "double3" : case "float3" : string $COMPOUNDATTR[] = `listAttr $WHOLE` ; for ($I = 1 ; $I <= 3 ; $I++) llIAWMakeIncrement ($ELEMENT , $COMPOUNDATTR[$I] , $OPERATION , $INCREMENT) ; break ; default : $ERRORS = $ERRORS + 1 ; break ; } ; // switch ($CURRENT_TYPE } ; // else } // if -- attribute was found in $ELEMENT else $ERRORS = $ERRORS + 1 ; } ; // for // output result message if ($ERRORS == 0) print ("// Result : Changed " + (`size $SELECTION`) + " attributes //\n") ; else if ($ERRORS < (`size $SELECTION`)) warning ("attributes could not be changed or found in some of the selected elements") ; else error ("specified attributes could not be changed or found in the selected elements") ; } ; // global proc llIAWExecute ////////////////////////////////// // llIncrementAttributes // ////////////////////////////////// // // MAIN PROC. Creates the main window. // // --> llIAWExecute // ///////////////////////////////// global proc llIncrementAttributes () { string $VERSION = "1.0" ; int $WIDTH = 250 ; int $HEIGHT = 135 ; if (`window -ex llIncrementAttributesWindow`) deleteUI llIncrementAttributesWindow ; window -title ("llIncrementAttributes v" + $VERSION) llIncrementAttributesWindow ; columnLayout -adj 1 -cat "both" 20 ; separator -style "none" -h 10 ; textFieldGrp -l "Attribute Name" -cw 1 80 -adj 2 llIAWAttributeName ; floatFieldGrp -l "Increment" -pre 3 -cw 1 80 -adj 2 llIAWIncrement ; separator -style "none" -h 5 ; radioButtonGrp -numberOfRadioButtons 4 -labelArray4 "Add" "Sub" "Mult" "Div" -cat 1 "left" 20 -cw 1 50 -cat 2 "left" 15 -cw 2 50 -cat 3 "left" 10 -cw 3 50 -cat 4 "left" 5 -cw 4 50 -sl 1 llIAWOperation ; separator -style "none" -h 10 ; columnLayout -adj 1 -cat "both" 50 ; button -l "GO!" -c llIAWExecute ; window -e -wh $WIDTH $HEIGHT -s 0 llIncrementAttributesWindow ; showWindow llIncrementAttributesWindow ; } ; // global proc llIncrementAttributes //////////////////////////////////////////////////////////////////////////////////////////////////// // // EoS llIncrementAttributes // ////////////////////////////////////////////////////////////////////////////////////////////////////