I created my first python script in blender, the purpose of which is to manipulate an animation. To be more precise, it loops over some F-curve and on some of its BEZIER segments, it changes the intermediate control points (left_handle and right_handle in blender speak). I am quite happy because the script does what it is supposed to do.
However, whenever I manipulate the animation otherwise (create a new keyframe or use the F-curve editor), the effects of the python script are undone. So I keep the editor window open and when needed, hover over it and do Alt-P; so by and large, the problem is only mildly annoying, but anyhow. Also, I meanwhile noticed that the scripted changes do survive a save, blender close and re-open. But the first added keyframe spoils it again.
Q: Did I miss some special call that needs to be made in order to make my scripted manipulations "permanent"?
For the record, here's the script, slightly shortened
import bpy import os fc = bpy.context.active_object.animation_data.action.fcurves loc_z_curve = fc.find('location', index=2) extrafactor = -1.5 * bpy.context.scene.gravity / bpy.context.scene.render.fps / bpy.context.scene.render.fps prevk = None for k in loc_z_curve.keyframe_points: if not prevk is None and prevk.interpolation == 'BEZIER': frames = (k.co - prevk.co)/3.0 dist = (k.co - prevk.co)/3.0 extra = extrafactor * frames * frames prevk.handle_right = prevk.co + frames prevk.handle_right = prevk.co + dist + extra k.handle_left = k.co - frames k.handle_left = k.co - dist + extra prevk = k