I would like to get a reference to a keyframe when I create it. Alas, keyframe_insert() returns a bool indicating success, not a handle to the keyframe.
In my application, each keyframe may need a different interpolation mode (or other parameter) so it seems good to do this at creation time. Consider doing the following for an object where dataset has many elements:
ob = bpy.context.active_object
prop='["MyParam"]'
for interp, value, frame_time in dataset:
ob['MyParam'] = value
ob.keyframe_insert(data_path=prop, frame=frame_time)
# interp = LINEAR or BEZIER or ...
# set this one appropriately: How?
The only thing I can see at the moment is seems complicated:
- get the fcurves from ob.animation_data.action.fcurves
- ask the fcurves collection to look for the one with the right data_path,
- go searching the fcurve for a keyframe with the right values
This seems to look like:
# go looking for it
curve = ob.animation_data.action.fcurves.find(prop)
pts = curve.keyframe_points
# pts.find(key) what is "key" other than "the identifier for the collection member."
# do I need a foreach() loop here?
What would the key parameter be? Is there a better way? This multiple-search step seems like it would get costly fast. Any hints/clues would be welcome.