Calling native Keyframe Point insertion with Python

Hello,
I am building an add-on that duplicates keyframes. My approach is:

  • iterate through the selected F-Curves and creating copies of the keyframes’ data
  • manipulate the copied keyframe data
  • write the new keyframes to the selected F-Curves using this code:
new_key = fcurve.keyframe_points.insert(keyframe.co[0], keyframe.co[1], options={"FAST"})
  • After everything is done, redraw all animation-related UI with region.tag_redraw

My questions are:

  • Is this the most performant way to approach this?
  • Is FCurveKeyframePoints.insert the fastest method to use for creating new keyframes?
  • Are there any existing Blender add-ons that do something similar or leverage native commands?

Thank you very much!

To me keyframe_points.insert seems slow. I didn’t know about the “Fast” option and never compared, but I usually use keyframe_points.add(1) to add one keyframe. The keyframe is added to the end of the list so I grab it directly from keyframe_points[-1]
and then I add the (frame, value) to the keyframe_points[-1].co
After adding all the keyframes and their values I’m updating the Fcurve.
This seemed to work much faster and smoother for me, but you can try to compare the 2

3 Likes

Thank you so much for the tip @TalHershkovich . You are a legend for Animation Layers. I love it!

1 Like