Follow path changes

I was trying to use bits from the 257 PDF Code Snippets document to script the adding of a follow path constraint. It wasn’t working so I tried the whole example, it too didn’t work.

After reading this I had a play with ‘Eavaluation Time’ in the ‘Path Animation’ panel. If I change current frame to 1 and set the evaluation time to 1 and insert a keyframe on evaluation time, then change both to 251 and insert another keyframe, then the example works.

However, how do I do this by script?
What is the keying set known as?


ob_curve=bpy.context.active_object
oc=ob_curve.data
oc.keyframe_insert('eval_time', index=0, frame=1)

Instead of ‘eval_time’ i’ve tried, ‘oc.eval_time’, ‘bpy.ops.anim.eval_time’, ‘Curve.eval_time’, ‘curve.eval_time’, ‘bpy.types.Curve.eval_time’, ‘evaluation_time’, ‘Evaluation Time’, and the list goes on, all to no avail…

I’ve also tried to get the name from an existing path made manually…


>>> ob=bpy.context.active_object
>>> action = ob.animation_data.action
Traceback (most recent call last):
  File "<blender_console>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'action'

>>> action = ob.animation_data
animation_data  animation_data_clear(  animation_data_create(
>>> action = ob.animation_data
>>> action
>>> print(action)
None

>>> type(action)
<class 'NoneType'>

But i’m obviously going wrong there…

Any ideas or solutions would be great!

get our latest script for ligth wizard set up
we got example of constraint but may be not this one
more constraint for object
and lot’s of other examples of code too for fun

salutations

I got it to work by dropping the index parameter.

This code assumes you have a curve named “cu_curve” (NOTE: Not the object, but the data named “cu_curve”)


cu = bpy.data.curves["cu_curve"]
cu.eval_time = 0
cu.keyframe_insert('eval_time',frame=5)
cu.eval_time = 100
cu.keyframe_insert('eval_time',frame = 15)

@Ricky, Where, what?

Excellent! Your a star Atom! :RocknRoll:

Here’s the full code.


import bpy


scn = bpy.context.scene
scn.frame_start = 1
scn.frame_end = 251

origin=(0,0,0)
# Create path data and object
path = bpy.data.curves.new('MyPath', 'CURVE')
pathOb = bpy.data.objects.new('Path', path)
pathOb.location = origin
bpy.context.scene.objects.link(pathOb)

# Set path data
path.dimensions = '3D'
path.use_path = True
path.use_path_follow = True
path.path_duration = 250

# Add a spline to path
spline = path.splines.new('POLY')
spline.use_cyclic_u = True
spline.use_endpoint_u = False
# Add points to spline
pointTable = [(0,0,0,0), (1,0,3,0),
    (1,2,2,0), (0,4,0,0), (0,0,0,0)]
nPoints = len(pointTable)
spline.points.add(nPoints-1)
for n in range(nPoints):
    spline.points[n].co = pointTable[n]

# Add a monkey
bpy.ops.mesh.primitive_monkey_add()
monkey = bpy.context.object

# Add follow path constraint to monkey
cns = monkey.constraints.new('FOLLOW_PATH')
#cns = monkey.constraints.new('FOLLOW')
cns.target = pathOb     #ob_curve
cns.use_curve_follow = True
cns.use_curve_radius = True
cns.use_fixed_location = False
cns.forward_axis = 'FORWARD_Z'
cns.up_axis = 'UP_Y'


# NEW - Adds evaluation time key frames
###############################
bpy.ops.anim.change_frame(frame = 1)
path.eval_time=1
path.keyframe_insert('eval_time', frame=1)

bpy.ops.anim.change_frame(frame = 251)
path.eval_time=251
path.keyframe_insert('eval_time', frame=251)

bpy.ops.screen.animation_play(reverse=False, sync=False)