# Creating smooth curves from collection of raw data points

I need to create a set of smooth curves (several thousand curves, in fact) from raw data that is in plain text files (i.e. not 3d objects). Each curve is made up of about 100-200 data points in the format (x, y, z).

I am aware, of course, that blender objects and curves can be generated via scripting in python, so this should be doable.

I was wondering if somebody could give me a pointer regarding a good starting point to get this done: any help (snippet, example, etc) would be super appreciated! Thank you!

• As a starting point, use the Python csv module. Read your points in from csv and use them to create spline curves. There are several questions about creating curves in Python with examples, like this old one that you can use. If you get stuck on a specific, ask a question here. Commented Jun 17, 2022 at 17:49

Just for completeness, I actually did some digging and found a solution that accepts a text file containing multiple lists of coordinates in the 'x y z' format, with different curves separated by a blank line. I have copy-pasted the example below in case it helps others!

import bpy
import csv
from mathutils import Vector

# we don't have to use the Vector() notation.
listOfVectors = [(0,0,0),(1,0,0),(2,0,0),(2,3,0),(0,2,1)]

def MakePolyLine(objname, curvename, cList):
#let's first start by opening the filename with data points.
trackpoints = "/Users/daviddc/Dropbox/archive/listofpoints.txt"
with open('/Users/daviddc/Dropbox/archive/listofpoints.txt') as csv_file:
line_count = 0
singleTrack = []
width = len(row)
if width > 0:
thisVec = (float(row[0]), float(row[1]), float(row[2]))
singleTrack.append(thisVec)
if width == 0:
#ah but wait, this means the track is now finished! create curve with it
print("Now drawing curve "+str(line_count))
curvedata = bpy.data.curves.new(name=curvename+str(line_count), type='CURVE')
curvedata.dimensions = '3D'

objectdata = bpy.data.objects.new(objname+str(line_count), curvedata)
objectdata.location = (0,0,0) #object origin

polyline = curvedata.splines.new('NURBS')
$$$$
`