Skip to content

Instantly share code, notes, and snippets.

@zeffii
Created July 15, 2015 17:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zeffii/c7f9a44e82357a2168ff to your computer and use it in GitHub Desktop.
Save zeffii/c7f9a44e82357a2168ff to your computer and use it in GitHub Desktop.
import os
import bpy
filename = 'non_standard.csv'
directory = '/home/zeffii/Desktop' # <-- if you have linux or osx
# directory = r'c:\some\directory' # <-- if windows, the r is important
# directory = 'c:/some/directory' # <-- if windows (alternative)
fullpath = os.path.join(directory, filename)
with open(fullpath, 'r', newline='') as csvfile:
# split every row at the comma,,
rows = (r.split(',') for r in csvfile if r)
# then take the first 3 values and cast them as float
verts = [[float(i) for i in r[:3]] for r in rows]
if verts:
out2 = []
[out2.extend(list(i)+[0.0]) for i in verts]
# first coordinate is present by default, we add the (number of total verts) - 1
num_points_to_add = len(verts) - 1
curve = bpy.data.curves.new("path_name", type='CURVE')
polyline = curve.splines.new(type='POLY')
polyline.points.add(num_points_to_add)
# a flatterened list of [x1, y1, z1, x2, y2 .... y20, z20]
polyline.points.foreach_set('co', out2)
obj = bpy.data.objects.new("obj_name", curve)
scene = bpy.context.scene
scene.objects.link(obj)
@matslemmens
Copy link

Long time user of this script.
Thank you for the original one.
I made a few corrections so it is compatible with the newer versions of Blender.

@matslemmens
Copy link

matslemmens commented Feb 13, 2024

Actually only one change is needed on line 34:

scene = bpy.context.collection

@zeffii
Copy link
Author

zeffii commented Feb 19, 2024

wow. 9 years ago :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment