Delete Bone keyframes from F-curves

I have created a function to delete object keyframes in range. Now, I’m creating the same functionality for a bone.

The function receives the bone, the type “Loc/Rot/Scale” and the frame range.

The loop read the curves and select only the Loc/Rot/Scale type and the bone using the name of the datapath.

This is the function:

import bpy

# Clear animation frames from Bone
# myBone: Bone to clear
# typ: Loc/Rot/Scale
def clearBoneAnimation(myBone,typ,fromFrame,toFrame):
     # Get current action name      
    ob = bpy.context.object
        action_name =
        return {'FINISHED'}
    if (action_name != None):
        a =    
        # Loop all f-curves
        for curve in a.fcurves:
            if curve.lock == False and curve.data_path[-len(typ):] == typ:
                if "[\"" + in curve.data_path:
                    keyframePoints = curve.keyframe_points
                    for keyframe in keyframePoints:
                        x =[0] # get frame number
                        # only delete frame range
                        if x >= fromFrame and x <= toFrame:
                            print("Removing keyframe")
                            #keyframePoints.remove(keyframe)  <<<<< HOW DELETE?
# Call funcion   
print("========= Running ==================")                     

The problem it’s the remove itself. I have tested several options but nothing works.

How can I delete the keyframe (X/Y/Z)?




I have tested a lot of things before your code but yours works perfect.

Thanks !

Looking to do something similar and ran into this. What was the resolution?