// This script sets an attribute to a value on every item it can in a selection list. // It is called in the form of: ms "attribute" "value" // Replace any \ with \\ or /, such as the \ in a directory path // This script will take alpha and numeric inputs, and will try to // find the attribute in a shape node if a transform node without the // specified attribut is encountered // Created by Alex Hogan on 05-03-2002 // proc string decideAndSetVar ( string $currentObject, string $userAtt, string $userVar ) { string $returnVal = "initialized"; // string $tokenedList[]; string $completeAttPath = $currentObject + "." + $userAtt; string $mcCheck1 = `getAttr -type $completeAttPath`; /* // debug spew print "mcCheck1 contains "; print $mcCheck1; print "\n"; $mcCheck2 = `whatIs "$mcCheck1"`; print "mcCheck2 contains "; print $mcCheck2; print "\n"; tokenize $mcCheck2 " " $tokenedList; print "tokenedList contains "; print $tokenedList[0]; print " "; print $tokenedList[1]; print "\n"; string $mcCheck3 = $tokenedList[0]; print "mcCheck3 contains "; print $mcCheck3; print "\n"; */ switch ($mcCheck1) { case "bool": $toInt = int( $userVar ); setAttr $completeAttPath $toInt; // print "\n"; // print "Variable type found to be bool"; // print "\n"; $returnVal = $mcCheck1; break; case "int": $toInt = int( $userVar ); setAttr $completeAttPath $toInt; // print "\n"; // print "Variable type found to be int"; // print "\n"; $returnVal = $mcCheck1; break; case "short": $toFloat = float( $userVar ); setAttr $completeAttPath $toFloat; // print "\n"; // print "Variable type found to be short"; // print "\n"; $returnVal = $mcCheck1; break; case "float": $toFloat = float( $userVar ); setAttr $completeAttPath $toFloat; // print "\n"; // print "Variable type found to be float"; // print "\n"; $returnVal = $mcCheck1; break; case "doubleLinear": $toFloat = float( $userVar ); setAttr $completeAttPath $toFloat; // print "\n"; // print "Variable type found to be doubleLinear"; // print "\n"; $returnVal = $mcCheck1; break; case "enum": $toFloat = float( $userVar ); setAttr $completeAttPath $toFloat; // print "\n"; // print "Variable type found to be enum"; // print "\n"; $returnVal = $mcCheck1; break; case "Unknown": print "Error: Data type for specified variable returned as \"Unknown\" for attribute "; print $completeAttPath; // print "\n"; $returnVal = $mcCheck1; break; case "string": setAttr -type "string" $completeAttPath $userVar; // print "\n"; // print "Variable type found to be string or default"; // print "\n"; $returnVal = $mcCheck1; break; default: print "Error: Data type did not match any recognized type : "; print $completeAttPath; print " "; print "Type : "; print $mcCheck1; print "\n"; $returnVal = $mcCheck1; break; } return $returnVal; } proc string[] getShape( string $xform ) { // If given node is not a transform, assume it is a shape // and pass it through. string $shapes[]; $shapes[0] = $xform; if ( "transform" == `nodeType $xform` ) { $shapes = `listRelatives -fullPath -shapes $xform`; } return $shapes; } global proc ms ( string $userAtt, string $userVar ) { $userVar = toNativePath( $userVar ); //convert \\ to \ and / to \ string $selectionList[] = `ls -sl`; string $tryThisThen[10]; string $insideNode; string $trying; for ($node in $selectionList) { if ( `attributeQuery -node $node -exists $userAtt` ) { // print "\nProcessing on selected or transform\n"; $trying = decideAndSetVar( $node, $userAtt, $userVar ); } else { $tryThisThen = getShape( $node ); for ($insideNode in $tryThisThen) { if ( `attributeQuery -node $insideNode -exists $userAtt` ) { // print "\nProcessing on shape\n"; $trying = decideAndSetVar( $insideNode, $userAtt, $userVar ); } else print ("Error - attribute not found: " + $insideNode + "." + $userAtt); } // print "\n"; // print $trying; } } }