I am trying to insert a keyframe at an object's "Follow Path" constraint programmatically. More specifically I am trying to insert a keyframe to the "Offset Factor" property of the constraint. Manually, I would constraint an object to follow a curve, select the desired frame and then right click on "Offset" -> "Insert Keyframe". However, blender's function:

object.keyframe_insert(data_path="location", frame=0)

Does not have a data_path option for the offset_factor. The "location" option is a handle to the object's location at creation (for my case (0,0,0)) and does not change with offset factor change. Is there a workaround or is it not a supported feature? In my code I am trying to set a keyframe at frame 0, offset=0 and at frame 100, offset=1:

constraint_handle.offset_factor = 0
object.keyframe_insert(data_path="location", frame=0)
constraint_handle.offset_factor = 1
object.keyframe_insert(data_path="location", frame=100)

1 Answer 1


Keyframe the constraint "object"

Same as [obj.keyframe_insert, bpy.data.particles["ParticleSettings"].lifetime]; how to insert keyframe to an existed particle setting, e.g lifetime only your object of concern to keyframe is the follow path constraint

Python console code

Object has a follow path constraint with default name

>>> ob = C.object
>>> ob.constraints['Follow Path']
bpy.data.objects['Eye.001'].constraints["Follow Path"]

Alternatively, all constraints on object of type follow path in a list

>>> constraints = [c for c in ob.constraints if c.type == 'FOLLOW_PATH']
>>> constraints
[bpy.data.objects['Eye.001'].constraints["Follow Path"]]

Getting by name, will be None if there is no constraint named "Follow Path"

>>> con = ob.constraints.get("Follow Path")

Ok, set and insert a keyframe for offset_factor at frame 1

>>> if con:
...     con.offset_factor = 0.0
...     con.keyframe_insert("offset_factor", frame=1)

True indicating the success of inserting the keyframe

  • $\begingroup$ Thank you! It works. I was inserting the keyframe to the object handle directly, which didn't have an offset_factor property. Much appreciated. $\endgroup$
    – Smilon
    Jul 3, 2020 at 14:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .