<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Getting the locked status of an attribute within a selected object in Maya Programming Forum</title>
    <link>https://forums.autodesk.com/t5/maya-programming-forum/getting-the-locked-status-of-an-attribute-within-a-selected/m-p/7251903#M11579</link>
    <description>&lt;P&gt;First time I posted this nothing happened! Hope it doesn't show up twice &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This should solve it.&lt;/P&gt;&lt;PRE&gt;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;
    }
}&lt;/PRE&gt;</description>
    <pubDate>Tue, 25 Jul 2017 09:08:28 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2017-07-25T09:08:28Z</dc:date>
    <item>
      <title>Getting the locked status of an attribute within a selected object</title>
      <link>https://forums.autodesk.com/t5/maya-programming-forum/getting-the-locked-status-of-an-attribute-within-a-selected/m-p/7247498#M11577</link>
      <description>&lt;P&gt;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&amp;nbsp;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's the script I'm trying to run:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;string $array[] = `ls -sl`;&lt;/P&gt;&lt;P&gt;int $Xlock;&lt;/P&gt;&lt;P&gt;int $Ylock;&lt;/P&gt;&lt;P&gt;int $Zlock;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;for ($item in $array)&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; $Xlock = getAttr -se ($item + ".translateX");&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; $Ylock = getAttr -se ($item + ".translateY");&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; $Zlock = getAttr -se ($item + ".translateZ");&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; if($Xlock !=&amp;nbsp;0)&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; {&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; setAttr ($item + ".translateX") 0;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; }&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; if($Ylock !=&amp;nbsp;0)&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; {&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;setAttr ($item + ".translateY") 0;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; }&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; if($Zlock !=&amp;nbsp;0)&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; {&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; setAttr ($item + ".translateZ") 0;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; }&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;</description>
      <pubDate>Sun, 23 Jul 2017 12:32:10 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/maya-programming-forum/getting-the-locked-status-of-an-attribute-within-a-selected/m-p/7247498#M11577</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2017-07-23T12:32:10Z</dc:date>
    </item>
    <item>
      <title>Re: Getting the locked status of an attribute within a selected object</title>
      <link>https://forums.autodesk.com/t5/maya-programming-forum/getting-the-locked-status-of-an-attribute-within-a-selected/m-p/7251892#M11578</link>
      <description>&lt;P&gt;Think I understood what you are after. You just want to skip over locked attributes.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So you missed the `` around the getAttr function, you need that when calling&amp;nbsp;it in a int or string etc.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also the locked return value is 0. You where stating&amp;nbsp;if it's not 0 then setAttr to&amp;nbsp;0 which wouldn't work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope that helps.&lt;/P&gt;&lt;PRE&gt;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;
    }
}&lt;/PRE&gt;</description>
      <pubDate>Tue, 25 Jul 2017 09:03:07 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/maya-programming-forum/getting-the-locked-status-of-an-attribute-within-a-selected/m-p/7251892#M11578</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2017-07-25T09:03:07Z</dc:date>
    </item>
    <item>
      <title>Re: Getting the locked status of an attribute within a selected object</title>
      <link>https://forums.autodesk.com/t5/maya-programming-forum/getting-the-locked-status-of-an-attribute-within-a-selected/m-p/7251903#M11579</link>
      <description>&lt;P&gt;First time I posted this nothing happened! Hope it doesn't show up twice &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This should solve it.&lt;/P&gt;&lt;PRE&gt;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;
    }
}&lt;/PRE&gt;</description>
      <pubDate>Tue, 25 Jul 2017 09:08:28 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/maya-programming-forum/getting-the-locked-status-of-an-attribute-within-a-selected/m-p/7251903#M11579</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2017-07-25T09:08:28Z</dc:date>
    </item>
    <item>
      <title>Re: Getting the locked status of an attribute within a selected object</title>
      <link>https://forums.autodesk.com/t5/maya-programming-forum/getting-the-locked-status-of-an-attribute-within-a-selected/m-p/7252718#M11580</link>
      <description>&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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!&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jul 2017 14:12:31 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/maya-programming-forum/getting-the-locked-status-of-an-attribute-within-a-selected/m-p/7252718#M11580</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2017-07-25T14:12:31Z</dc:date>
    </item>
  </channel>
</rss>

