make attribute not keyable

32 views
Skip to first unread message

Rudi Hammad

unread,
Jul 21, 2021, 7:54:59 AMJul 21
to Python Programming for Autodesk Maya

Hello,
to make an attribute not keyable you can do it with cmds or mplug or right click 'make not keyable'. What this does is grey out the channel box, so if you select the node and set a key typing 's', the attribute is not keyed. So far so good.

Now, this is what I find annoying. Many times when animating you just select the channel box attributes (so not the node) and type 's'. In this case even if it set not to be keyable, it will add a key, so it is not really unkeyable. So is it possible to make it 100% unkeyable?


Side note: I find odd that the api uses the method MPlug.setKeyable() to hide and MPlug.setChannelBox() to make keyable. A bit confusing isn't it?

R

Marcus Ottosson

unread,
Jul 25, 2021, 2:41:15 PMJul 25
to python_in...@googlegroups.com

Yes, the jargon here is terrible. Likely for legacy reasons. (Although I can’t think of which ones exactly? I remember this being fuzzy way back in Maya 4.0)

But, it isn’t true that the s hotkey puts a key on non-keyable attributes, can you confirm?

  1. Create cube
  2. Make translateY, translateZ and rotateX non-keyable
  3. Hit s

You should find all attributes in the channel box have a key, except for those three.

But, as far as I know, only the s key respects this attribute. And the s key is mostly a wasted keyboard shortcut. (How often do you intend on keying every single keyable attribute?) More usable means disregards the non-keyable state (perhaps for the better).

  1. Shift + w still keys translateY and translateZ, regardless of their non-keyable state
  2. Right-click on rotateX to Key Selected still produces a key, again regardless of their non-keyable state.

Some tools do respect the non-keyable state, like Edit -> Bake Simulation and creating a new animation layer.

So, unlike the locked state the non-keyable state is more of a hint. Some metadata that tools may choose whether or not to respect, with a slight hint in the channel box for the animator that the attribute isn’t intended to be keyed. With that in mind, one way of making a channel 100% unkeyable is by making it locked, although that typically isn’t a practical use for the locked state. Another is by making it un-connectable, since a keyed channel is merely one that is connected to a keyframe node, like animCurveTL.

I wasn’t able to find a way of doing this via cmds, maybe someone else knows?

from maya.api import OpenMaya as om

cmds.file(new=True, force=True)
cube, _ = cmds.polyCube()
sl = om.MSelectionList()
sl.add(cube)
mobj = sl.getDependNode(0)
fn = om.MFnDependencyNode(mobj)
plug = fn.findPlug("translateX", False)
plug.name()
fna = om.MFnAttribute(plug.attribute())
fna.connectable = False

cmds.setKeyframe(v=10, at="translateX")  # Fail!

The API does sometime allow metadata like this to be edited without actually being able to save it with the scene (e.g. MFnAttribute.setNiceNameOverride), especially not for native plugs like this one. But this does appear to save and load fine. This would make an attribute truly non-keyable, whilst still allowing it to be edited (unlike a locked attribute).


--
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_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/b210fbff-2a8f-4c63-a914-da9eb7547d5cn%40googlegroups.com.
Message has been deleted

Rudi Hammad

unread,
Jul 25, 2021, 7:04:29 PMJul 25
to Python Programming for Autodesk Maya
edited

"Right-click on rotateX to Key Selected still produces a key, again regardless of their non-keyable state."

Yes, sorry, that is what I meant. The "s"  doesn't create the key, but right-click and key creates a key. That is what was bugging me.
The solution whould be set connectable to False, but the problem is that if you close maya and open a new session  it reverts it to keyable, so it doesn't really save if you close your session.

By the way, after running your code, since connectable was set to False, any new dag node you create will have the translateX not connectable. Is that a static variable and that's
why it propagates through each new node that is created? we'll need to be careful to set back to True.

Interesting stuff...

Marcus Ottosson

unread,
Jul 26, 2021, 3:35:42 AMJul 26
to python_in...@googlegroups.com

The solution whould be set connectable to False, but the problem is that if you close maya and open a new session it reverts it to keyable, so it doesn’t really save if you close your session.

Ah that’s a bummer. Now that I think of it, that’s what happens to setNiceNameOverride too, even when editing your own custom attributes. Quite misleading. I expect those properties are solely meant for creating new attributes rather than editing existing ones. The translate attributes are probably special since they are native and not plug-in based, but the closest similarity might be to extension attributes. Which I understand as a kind of “instanced” attribute.


stephenkmann

unread,
Jul 26, 2021, 1:11:41 PMJul 26
to python_in...@googlegroups.com
I've been pushing for "un-keyable" to actually be un-keyable for years.. ( maybe even a decade?) 

 I'm not exactly sure what the reasoning behind allowing un-keyable channels  to still be keyed is.

-=s



--

Marcus Ottosson

unread,
Jul 26, 2021, 4:34:46 PMJul 26
to python_in...@googlegroups.com

It would be fickle, because what does “keyable” mean?

In Maya, an attribute of one node can connect to an attribute of another node. Sometimes, that other node is a animCurveTL which we then perceive as being “keyed”. But there’s nothing differentiating the animCurveTL.output attribute from a someTransform.translateX attribute. So, it would have to be completely unconnectable. But that means it also cannot be simply driven by another attribute, like an animation control. It would be very limiting.

What maybe could happen though, is for that right-click menu and Shift + w to respect the non-keyable state. And that may be doable. Ideally by Autodesk, but even by us as both of those are (probably?) MEL commands that can be overridden post-launch. Anyone care to take a crack at it?


Reply all
Reply to author
Forward
0 new messages