Using find() method to get index of a keyframe_point on fcurve?

I’m trying to understand what to pass to the

fcurves.keyframe_point.find() 

method to get the index of a keyframe_point on an fcurve. Is this even possible? Do I have to iterate through keyframe_points using indices instead? I’d like to not have to, if it’s not necessary.

For instance, if I’m doing

fcurves = C.object.animation_data.action.fcurves
for fcu in fcurves:
    for kp in fcu.keyframe_points:
        #What can I do here to return the index of the current kp?

that find() is apprently useless, use keyframe_points.items() or

for index, point in enumerate(FCurve.keyframe_points): …

if you wanna access a certain keyframe point at some point, use a variable to store a reference to that keyframe point instead of its index.

Ah, ok. Man, the time I wasted trying to figure out why nothing would work!

Thanks!

Super old topic but I found fcurves.keyframe_point.find() to work as long as you pass data_path as unnamed parameter, and index as a named parameter.

I did find it easier though to iterate over a list comprehension of fcurves where the data_path fits the given value, this way it will apply to each axis (index) with that type.

import bpy; D = bpy.data

cube = D.objects.get("Cube")

# jumbled insertion order
cube.location = (10,0,0); cube.keyframe_insert(data_path='location', frame=72)
cube.location = (0,10,0); cube.keyframe_insert(data_path='location', frame=24)
cube.location = (0,0,0); cube.keyframe_insert(data_path='location', frame=96)
cube.location = (10,10,0); cube.keyframe_insert(data_path='location', frame=48)
cube.location = (0,0,0); cube.keyframe_insert(data_path='location', frame=1)

print(cube.animation_data.action.fcurves.find('location',index=0)) #x
print(cube.animation_data.action.fcurves.find('location',index=1)) #y
print(cube.animation_data.action.fcurves.find('location',index=2)) #z

# iterate keyframes over all axis (fcurve index), but only 'location' fcurves
for keyframes in [fcurve.keyframe_points for fcurve in cube.animation_data.action.fcurves if (fcurve.data_path=='location')]:
    # keypoints index in chronological (timeline) order, i.e, keyframes[-1] is latter most keyframe, irrespective of insertion order
    print(keyframes[0].co); keyframes[0].interpolation = 'BEZIER'
    print(keyframes[1].co); keyframes[1].interpolation = 'LINEAR'
    print(keyframes[2].co); keyframes[2].interpolation = 'CONSTANT'
    print(keyframes[3].co); keyframes[3].interpolation = 'LINEAR'
    print(keyframes[-1].co); #interpolation type of final keyframe (frame 96) has no effect