How to move the keyframes for specified shape keys with Python I've created an object that has a few shape keys that have keyframes inserted. I've made a script that moves keyframes for shapekeys, but I can't get it to work for individual shape keys ones. Instead, the script moves the keyframes for all of the shapekeys in the scene. Does any one have an idea of how to get a specific objects keyframes moved?

Code:

for key in bpy.data.shape_keys:
    if key.animation_data is not None:
        action = key.animation_data.action
        if action is not None:
            for fc in action.fcurves:
                for kf in fc.keyframe_points:
                    kf.co.x += 90  


Let's say I have a key named "Key 2" and I want the keyframes for only that shape key to be affected. This script simply doesn't function to do so.

I've searched and tried many methods including using lists or variables like this (to only alter the shape key of a selected object):

ob = bpy.context.scene.objects

sel_shape_keys = ob.active.data.shape_keys

for key in sel_shape_keys:
    if key.animation_data is not None:
        action = key.animation_data.action
        if action is not None:
            for fc in action.fcurves:
                for kf in fc.keyframe_points:
                    kf.co.x += 90   


but I get error messages every time. I'll admit that I'm a bit new to working with keyframes in Blender's Python API - any help with this would be greatly appreciated as I'm stumped in solving the issue.
This script gives you the ability to list the names of the shapekeys you want to shift, then move only them by the keyframeInterval value you want.

It uses a regular expression pattern to match the shapekey name to the fcurve data path string.

import bpy, re

o = bpy.context.object

sk  = o.data.shape_keys
act = sk.animation_data.action if sk and sk.animation_data else None

keyframeInterval = 10 # Number of frames to move shape keys
keysToShift = ['Key 2', 'Key 3'] # List of shape keys you want to move (names)

# Regular expression pattern to find key in fcurve data path.
# Example: 'key_blocks["Key 1"].value'
pat = '^key_blocks\["(.+)"\]\.value$'

if act:
    for fc in act.fcurves:
        m = re.match( pat, fc.data_path )
        if m and m.groups() and m.groups()[0] in keysToShift:
            for kf in fc.keyframe_points:
                kf.co.x += keyframeInterval