I want to move a soft body object in my scene on a path (curve path). For the path, I want to make it myself from scratch. I basically have a Python List containing (x, y, z) points and want to create a curve path from scratch given these points using a Python script. However, it looks like the way the vertices are stored for paths is different than meshes as I cannot find something like nurbsPathObj.data.vertices. So I wonder, how can I manually add new vertices to a path or remove some of them via Blender's Python API?

  • $\begingroup$ What kind of path? Do you mean a curve? $\endgroup$ – brockmann Oct 8 '18 at 18:16
  • $\begingroup$ @brockmann Edited the question. I think it should be more clear now $\endgroup$ – Amir Oct 8 '18 at 18:19
  • 2
    $\begingroup$ Take a look on this: blender.stackexchange.com/questions/6750/… $\endgroup$ – Yann Masoch Oct 8 '18 at 18:43

Maybe something like this? See also: Create NURBS surface with Python

import bpy
from mathutils import Vector

coords_list = [[0,1,2], [1,2,3], [-3,2,1], [0,0,-4]]

# make a new curve
crv = bpy.data.curves.new('crv', 'CURVE')
crv.dimensions = '3D'

# make a new spline in that curve
spline = crv.splines.new(type='NURBS')

# a spline point for each point
spline.points.add(len(coords_list)-1) # theres already one point by default

# assign the point coordinates to the spline points
for p, new_co in zip(spline.points, coords_list):
    p.co = (new_co + [1.0]) # (add nurbs weight)

# make a new object with the curve
obj = bpy.data.objects.new('object_name', crv)

To add a point at the end it's simply:

spline = bpy.data.objects["object_name"].data.splines[0]
spline.points[-1].co = (1,1,5,1)

or to add more points at the end:

more_coords = [...list of more coords...]
for p, new_co in zip(spline.points[-len(more_coords):]:
    p.co = new_co + [1] # if new_co is a list [x,y,z]

You can always get the coords of the points of the spline with

points_coords = [p.co for p in spline.points]

edit this list, i.g.

points_coords = points_coords[3:5] + [1.5,2,2.5,1] + points_coords[5:]

and then remove the spline or object and make a new one with the updated coordinates.

| improve this answer | |
  • $\begingroup$ how to make this working for version 2.8? $\endgroup$ – Fabio Jul 26 '19 at 17:55

An update for Blender 2.8


is now




needs to pass a number

| improve this answer | |

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.