- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have a script that sets keyframes on an object. If the base animation layer is locked, the keyframe does not get set. I tried adding code to unlock the base animation layer, set the keyframe, and then relock it. This does not work. However, if I manually unlock the layer and THEN run my script, it works.
Reproducing the problem:
Create a new scene. Add an object (cube, sphere, whatever) to the scene. Set a couple of keys on the object. Now create a new animation layer with nothing in it. Lock the base animation layer.
Select the object, and run the code below. The keyframe does not get set.
Sample code:
def setKeyOnSelected(frameNumber, value):
selObjs = cmds.ls(sl=True, o=True)
currTime = cmds.currentTime(q=True)
cmds.currentTime(frameNumber)
baseLayer = cmds.animLayer(q=True, root=True)
if baseLayer:
baseLayerLockState = cmds.animLayer(baseLayer, q=True, lock=True)
cmds.animLayer(baseLayer, edit=True, lock=False)
for obj in selObjs:
cmds.move(value, 0, 0, obj)
res = cmds.setKeyframe(obj)
print res
cmds.currentTime(currTime)
if baseLayer:
cmds.animLayer(baseLayer, edit=True, lock=baseLayerLockState)
setKeyOnSelected(10, 5)
Is this a bug, or do I have some fundamental misunderstanding about animation layers and setting keyframes?
Solved! Go to Solution.