1
$\begingroup$

I need to create a keyframe for scale object "target" at time "time" with slope "fast" My code right now looks like that:

bpy.data.objects[target].keyframe_insert(data_path='scale', frame = time)

But how can I select this keyframe and set easing for it with python? Or should I create it in a different way?

Regards

$\endgroup$
0
$\begingroup$

To select the keyframe points with frame = time of the scale fcurves, and set easing to 'EASE_IN'

import bpy

context = bpy.context
obj = context.object

action = obj.animation_data.action
fcurves = [fc for fc in action.fcurves if fc.data_path == "scale"]
#fcurve = action.fcurves.find("scale", index=0) # location.x fcurve
time = 1 # frame
for fcurve in fcurves:
    # iterate thru keyframe Points and change easing of those at frame = time
    for kfp in fcurve.keyframe_points:
        # ('AUTO', 'EASE_IN', 'EASE_OUT', 'EASE_IN_OUT')
        if kfp.co.x == time:
            print("scale.%s easing set to EASE_IN at frame %d" % ("xyz"[fcurve.array_index], time))
            kfp.easing = 'EASE_IN' #  auto 

alternatively can create an action, fcurve and keyframe points eg make a new action with scale fcurves and add one keyframe (40, 3.9) with easing 'AUTO'.

import bpy
context = bpy.context
# create a new action and assign it to object
action = bpy.data.actions.new("ScaleAction")
context.object.animation_data.action = action
# fcurve data_path
data_path = "scale"
# (frame, value) for keyframe point
time = 40
value = 3.9
for axis in [0, 1, 2]:
    # new fcurve
    fc = action.fcurves.new(data_path, index=axis)
    # add a new keyframe point
    fc.keyframe_points.add(count=1)
    for kfp in fc.keyframe_points:
        kfp.co = (time, value)
        kfp.easing = 'AUTO'
| improve this answer | |
$\endgroup$

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.