4
$\begingroup$

I am currently trying to make an import script that generates an animation on a camera. The animation requires that the values for the left and right keyframe handles be set.

I couldn't find a way to set handle values explicitly, so I have tried to use bpy.ops.graph.select_border to select the keyframe handle that I want to set and then use bpy.ops.transform.translate to set it into place, however when I try to do this from my import operator, I get a RuntimeError saying context is incorrect

Does anyone know if the x and y handle values for an FCurve keyframe can be set from Python?

$\endgroup$
5
$\begingroup$

You will find it here:

action=bpy.data.actions['yourAction']
#or
action=bpy.data.objects['yourObject'].animation_data.action
#
action.fcurves[fcurve_index].keyframe_points[kf_index].left_handle
action.fcurves[fcurve_index].keyframe_points[kf_index].right_handle

You can easily explore blender's data structures with the outliner using the datablocks option and the interactive python console using autocompletion (Ctrl+Space).

If you hover over properties in the editor with python tooltips enabled it often will show you the path to the property.

Hint:

If the object has not been animated yet and thus animation_data is None, use the object's method animation_data_create to create it.

Afterwards assign an existing action to animation_data.action or create a new one:

action=bpy.data.actions.new('Your Name')

Note to the developers of blender:

In this case the path shown in the graph editor is abbreviated bpy.data.objects...left_handle and it is not possible to right click -> copy data path. So the hint shown is kind of useless.

$\endgroup$
  • $\begingroup$ thanks for your answer, the keyframe_point collection was marked as read only in the documentation which is why I assumed setting the keyframes from there won't work $\endgroup$ – Radu Chivu Jan 30 '14 at 15:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.