1
$\begingroup$

I generated a curve using the following python code

curve = bpy.data.curves.new("Curve", type='CURVE')
polyline = curve.splines.new(type='POLY')
polyline.points.add(n - 1) # The polyline has one point when created
polyline.points.foreach_set('co', data) # data is the array of coordinates

This works perfectly in generating the data I want. And now I want to create an animation for this curve by using pre-calculated data stored in a file.

Thus I am trying to use in a different script the following:

curve= bpy.data.objects["Curve"]
# for i ...
    # get new data
    curve.data.splines.foreach_set("location", data)
    curve.keyframe_insert(data_path="location", frame=i)

I tried different variations of the above segment to find a way to get to the points in the splines but no attributes exist for that.

Any suggestions?

$\endgroup$
1
$\begingroup$

Apparently the answer is simple to this, I had to choose splines[0]

curve = bpy.data.objects["Curve"]
points = cable.data.splines[0].points
# for i ...
    # get new data
    points.foreach_set("co", data)
    for point in points:
        point.keyframe_insert(data_path="co", frame = i)
$\endgroup$
  • $\begingroup$ Cool, I was going to suggest using hooks or shapekeys. $\endgroup$ – batFINGER Feb 14 '17 at 10:36

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.