Some further investigation, it looks like this only happens on *dynamic*
attributes, which is where I originally had the probelm, and doesn’t
actually happen in my example of translateX (which isn’t dynamic).

Here’s a reproducible.

from maya.api import OpenMaya as om

cmds.file(new=True, force=True)

fn = om.MFnDagNode()
mobj = fn.create("transform", "myName")
cmds.addAttr("myName", ln="size", keyable=True, at="float")
mplug = fn.findPlug("size", False)
mplug.isKeyable = False

cmds.file(rename="temp.ma")
cmds.file(save=True, type="mayaAscii")
cmds.file("temp.ma", open=True, force=True)

Following this, you should find a transform node myName with a size
attribute in the Channel Box. However, if you replace isKeyable with setAttr,
it’s hidden as expected.

from maya.api import OpenMaya as om

cmds.file(new=True, force=True)

fn = om.MFnDagNode()
mobj = fn.create("transform", "myName")
cmds.addAttr("myName", ln="size", keyable=True, at="float")
cmds.setAttr("myName.size", keyable=False)

cmds.file(rename="temp.ma")
cmds.file(save=True, type="mayaAscii")
cmds.file("temp.ma", open=True, force=True)

You can also see in the resulting .ma file that when setting isKeyable on
translateX, it makes an entry involving setAttr -k off. However, when
setting it for a dynamic attribute like size, it doesn’t make that.

What’s interesting is that, what *does* happen for a dynamic attribute is
that when calling setAttr(keyable=False) it modifies the original addAttr
command, from..

createNode transform -n "myName";
    addAttr -ci true -k true -sn "size" -ln "size" -at "float";

To..

createNode transform -n "myName";
    addAttr -ci true -sn "size" -ln "size" -at "float";

See the missing -k true? So even though I passed keyable=True to the
original addAttr from Maya, Maya is “smart” enough to know that if you also
change the keyable state with an additional setAttr command, it edits the
one previously added.

Setting isKeyable = False doesn’t affect the resulting ascii file at all.

Smells like a bug.
​

On 17 July 2018 at 20:46, Justin Israel <justinisr...@gmail.com> wrote:

>
>
> On Wed, Jul 18, 2018, 6:11 AM Marcus Ottosson <konstrukt...@gmail.com>
> wrote:
>
>> Hi all,
>>
>> Hiding an attribute from the channel box can be done with..
>>
>> from maya import cmds
>>
>> node = cmds.createNode("transform")
>> cmds.setAttr(node + ".translateX", keyable=False)
>>
>> And the equivalent from the API..
>>
>> from maya.api import OpenMaya as om
>>
>> fn = om.MFnDagNode()
>> mobj = fn.create("transform")
>> mplug = fn.findPlug("translateX", False)
>> mplug.isKeyable = False
>>
>> But! Upon saving and reopening the scene, the hidden state persist with
>> cmds.setAttr, but not with isKeyable = False. Tested in Maya 2015, SP6.
>>
>
> Does "mplug.isChannelBox = False" be have the same way with not saving the
> state with the scene?
>
>> Any idea how I can have it be saved with the scene?
>>
>> Best,
>> Marcus
>> ​
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Python Programming for Autodesk Maya" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to python_inside_maya+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit https://groups.google.com/d/
>> msgid/python_inside_maya/CAFRtmOCiE65wDA8CiB2mUVhhqOf2r
>> byAd%2BkKH8fCn4UimW-gVw%40mail.gmail.com
>> <https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOCiE65wDA8CiB2mUVhhqOf2rbyAd%2BkKH8fCn4UimW-gVw%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Python Programming for Autodesk Maya" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to python_inside_maya+unsubscr...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/python_inside_maya/CAPGFgA3ADbdXjPz6MJNnYjgX_
> FWh1Hhb9B2Cio5drywD2M91LA%40mail.gmail.com
> <https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA3ADbdXjPz6MJNnYjgX_FWh1Hhb9B2Cio5drywD2M91LA%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to python_inside_maya+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CAFRtmODiSfsDEG%3DSm%3DcbpfrFb3_po7hSwM%3DfytxoXhnQE6S6yw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to