Insert fcurve keyframe point whilst keeping curve shape

I have 2 keyframe points on an fcurve with free bezier handles, and using Python I want to insert a point in between these keyframes whilst keeping the custom shape of the curve with the handles. I can insert a keyframe point no problem using

fCurve.keyframe_points.insert(frame, value)


but I'm not sure how to do so without affecting the shape of the fcurve. Is this possible?

• You would need to read the value at that frame and then insert a keyframe with that value, if you want to insert one but not change the f-curve. – Anthony Forwood Jul 7 '16 at 19:38
• I can get the value at a keyframe between the points no problem, but the issue is if either of the existing points has free handles which have been moved to change the shape of the fcurve, then inserting a point won't keep that shape. I'm wondering if there is a way to insert a value (which I know lies on the curve) whilst keeping the custom shape defined by the handles? – Rajveer Jul 7 '16 at 19:42
• This is actually relatively straightforward. The Python API has access to the coordinates of the keyframe_points of the fcurve .co and the handles .handle_left and .handle_right. You can create a new point between the other two and set up the handles using De Casteljau’s Algorithm : clear.rice.edu/comp360/lectures/BezSubd.pdf – Mutant Bob Jul 7 '16 at 20:04
• possible duplicate of blender.stackexchange.com/questions/45311/… – Mutant Bob Jul 8 '16 at 14:51
• Thank you, I've almost got it working with the snippets. The only problem is that I want to add a point at a particular keyframe between 2 existing keyframes, rather than at a time t along the Bezier path (e.g. midway between 2 keyframes isn't necessarily midway along the curve, so I can't use t = 0.5). I can't find if the Python API exposes the time t for a point on an f-curve or if I'm just missing something obvious :) – Rajveer Jul 11 '16 at 16:21