iteratively key shape keys only on active object I need to keyframe shape keys and have a script that's nicely working -
import bpy


frames = bpy.context.scene.frame_end + 1


for frame in range(frames):
    for shapekey in bpy.data.shape_keys:
        for i, keyblock in enumerate(shapekey.key_blocks):
            if keyblock.name != 'Basis':
               curr = i - 1
               if curr != frame:
                   keyblock.value = 0
                   keyblock.keyframe_insert(&quot;value&quot;, frame=frame)
               else:
                   keyblock.value = 1
                   keyblock.keyframe_insert(&quot;value&quot;, frame=frame)
                   
                   

The issue is, I need it to work only on the active object, not every object in the scene.
Anyone any pointers?
Will this do?
import bpy

frames = bpy.context.scene.frame_end + 1

# For the active object...
ob = bpy.context.active_object
me = ob.data

# Remove ['Basis'] from a shallow copy of *ob's* shape-keys list.
kblocks = dict(me.shape_keys.key_blocks)
del kblocks['Basis']

# Keyframe shapekeys' values to 1 for the frame corresponding
# to their position in remaining list, 0 for other frames
for f in range(frames):
    for i, kb in enumerate(kblocks):
        kblocks[kb].value = (f == i)
        kblocks[kb].keyframe_insert(&quot;value&quot;, frame=f)

This may get burned down by a proper Pythonista.. :)