Created
July 15, 2015 17:40
-
-
Save zeffii/c7f9a44e82357a2168ff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Actually only one change is needed on line 34:
scene = bpy.context.collection
wow. 9 years ago :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.