Standardizing an Attribute

Now we’ll take the method from the previous post, Selecting by Type, to its next logical conclusion: manipulating the selections’ attributes. With MEL, attributes are identified as <nodename.attributename>. For example if you have a material ‘lambertBlue’ with a bump depth attribute, you would access it in MEL as lambertBlue.bumpDepth. So far so good!

Now, say that all of the textures in our scene have bump depths that are WAY too high, and we want to clamp them down across the board to a maximum of 0.1. First we’ll list everything with a nodeType of “bump2d” and then we’ll access the bumpDepth attribute. If the bump depth is greater than 0.1 we’ll change it 0.1, but if it’s less than that we’ll let it ride.

//This script changes all the bump depth values to 0.1. 
//
global proc standardizeBumpDepth()
{
     string $allTexs[] = `ls -l`;
     string $eachTex;
     for ( $eachTex in $allTexs) 
     {
         if ( `nodeType $eachTex` == "bump2d" ) 
         {
             //print ($eachTex + "\n");
             string $fileBump = $eachTex + ".bumpDepth";
             print($fileBump + "\n");
             float $bumpVal = `getAttr $fileBump`;
             print("Bump Value: " + $bumpVal + "\n");
             if($bumpVal > 0.1)
             {
                 print("THIS IS TOO HIGH! \n");
                 setAttr $fileBump 0.1;
             }
         }
     }
}

Leave a Reply

Your email address will not be published. Required fields are marked *