Zero Out Attributes and skip the Lock Attributes


#1

Hi

I have this script below that works until one of the attributes is locked and then it stopped working. For instance, if Translate X is locked, it will not continue with other attributes.


for ($selection in `ls -sl`){
    setAttr ($selection +  ".tx") 0;
    setAttr ($selection +  ".ty") 0;
    setAttr ($selection +  ".tz") 0;
    setAttr ($selection +  ".rx") 0;
    setAttr ($selection +  ".ry") 0;
    setAttr ($selection +  ".rz") 0;
    setAttr ($selection +  ".sx") 1;
    setAttr ($selection +  ".sy") 1;
    setAttr ($selection +  ".sz") 1; 
} 

So I was thinking an if statement command, but it does not seem to work. See code below:


$list = `ls -sl`;
print $list;


for ($lockList in $list){
    $lockCheckTX = `getAttr -l ($lockList + ".tx")`;
    if ($lockCheckTX < 0){
        setAttr ($lockList + ".tx") 0;
    }
    $lockCheckTY = `getAttr -l ($lockList + ".ty")`;
    if ($lockCheckTY < 0){
        setAttr ($lockList + ".ty") 0;
    }
    $lockCheckTZ = `getAttr -l ($lockList + ".tz")`;
    if ($lockCheckTY < 0){
        setAttr ($lockList + ".tz") 0;
    }
      
}

I guess an easier code for this is the listAttr command but for learning reason I would still like to have a solution of an if statement inside a for loop.

Thank you for taking look at the problem.


#2

Well there is the makeIdentity command which does this for you already. But anyway in your code, the problem is you are using the lessthan comparison for some reason. When you check for a lock, getAttr would return either 0 for unlocked, or 1 for locked, you will never get < 0.

You could write it like:

if ($lockCheckTX == 0) // ... 

or

if ($lockCheckTX != 1) // ... 

but better yet:

if (!$lockCheckTX) // ...

P.S. On line 15, you probably want “$lockCheckTZ” instead of “TY”


#3

Hi Spire. Thanks for the reply. Indeed that suggestion of yours works as expected.
And thanks for pointing out the makeIdentity command. Never knew that command existed.


#4

setting attributes to zero and freezing the transforms (makeIdentity) are completely different things


#5

depends if affecting descendants matters but in any case “freezing transformations” is only one particular use of makeIdentity which has absolutely nothing to do with this thread other than your compulsion to randomly necro and opine about it

ps i hope my sentences r l33t enuff 4u 2 c0mpr3h3nd