Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

Getting the locked status of an attribute within a selected object

Getting the locked status of an attribute within a selected object

Anonymous
Not applicable
3,846 Views
3 Replies
Message 1 of 4

Getting the locked status of an attribute within a selected object

Anonymous
Not applicable

Hi all. So I have a hotkey that I recently set up that zeroes out the translation of an object that I have selected, and I'm absolutely loving it. But the way I had it set up before, I wasn't able to use it for any object that I had with a locked axis. I'm working on a facial rig right now and I would definitely want to be able to use it for those controllers as well.

 

So I attempted to add a getAttr command with a -settable flag to run a check before the script tries to set an attribute, but I've been getting an invalid use error. I can use the flag no problem if I point to a specific object, but I don't know how to use it yet when dealing with $item. Can someone point me in the right direction?

 

Here's the script I'm trying to run:

 

string $array[] = `ls -sl`;

int $Xlock;

int $Ylock;

int $Zlock;

 

 

for ($item in $array)

{

    $Xlock = getAttr -se ($item + ".translateX");

    $Ylock = getAttr -se ($item + ".translateY");

    $Zlock = getAttr -se ($item + ".translateZ");

 

    if($Xlock != 0)

    {

        setAttr ($item + ".translateX") 0;

    }

    if($Ylock != 0)

    {

         setAttr ($item + ".translateY") 0;

    }

    if($Zlock != 0)

    {

        setAttr ($item + ".translateZ") 0;

    }

}

0 Likes
Accepted solutions (1)
3,847 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable

Think I understood what you are after. You just want to skip over locked attributes. 

 

So you missed the `` around the getAttr function, you need that when calling it in a int or string etc. 

Also the locked return value is 0. You where stating if it's not 0 then setAttr to 0 which wouldn't work.

 

Hope that helps.

string $selection[] = `ls -sl`;

for ($item in $selection)
{
    int $Xlock = `getAttr -l  ($item + ".translateX")`; //need the `` for the function.
    int $Ylock = `getAttr -l  ($item + ".translateY")`;
    int $Zlock = `getAttr -l  ($item + ".translateZ")`;
    print ("Xlock is "+$Xlock);

    if($Xlock == 0) // 0 = unlocked
    {
        setAttr ($item + ".translateX") 0;
    }
    if($Ylock == 0)
    {
        setAttr ($item + ".translateX") 0;
    }
    if($Zlock == 0)
    {
        setAttr ($item + ".translateX") 0;
    }
}
Message 3 of 4

Anonymous
Not applicable
Accepted solution

First time I posted this nothing happened! Hope it doesn't show up twice 🙂 

This should solve it.

string $selection[] = `ls -sl`;

for ($item in $selection)
{
    int $Xlock = `getAttr -l  ($item + ".translateX")`; //need the `` for the function.
    int $Ylock = `getAttr -l  ($item + ".translateY")`;
    int $Zlock = `getAttr -l  ($item + ".translateZ")`;
    print ("Xlock is "+$Xlock);

    if($Xlock == 0) // 0 = unlocked
    {
        setAttr ($item + ".translateX") 0;
    }
    if($Ylock == 0)
    {
        setAttr ($item + ".translateX") 0;
    }
    if($Zlock == 0)
    {
        setAttr ($item + ".translateX") 0;
    }
}
Message 4 of 4

Anonymous
Not applicable

That does exactly it! Thanks GF_mal! I didn't know about the `` thing, so knowing about it now is going to be a big help. I kind of wish there was an easier way to figure out all of Mel's syntax quirks, but I'll figure it out as I go I guess haha.

 

And I was originally planning to use the -settable flag which returns 1 when settable and 0 otherwise (when it's locked or connected, it's "not settable"), which is why I was stating for "if it's not 0" haha. But the script you gave me was exactly what I was attempting to do anyways, so the -lock flag works for me too. Thanks!

0 Likes