Hello fellow Blender snakehandlers,
I have a list of coordinates in a csv file and I would like to create a mesh with only vertices from it.
When I run it, it throws the following error, which I can't decipher. Any ideas on how to make this work? Thank you!
line 54, in <module>
File "C:\Program Files\Blender Foundation\Blender\2.79\scripts\modules\bpy_types.py", line 429, in from_pydata
self.vertices.foreach_set("co", tuple(chain.from_iterable(vertices)))
TypeError: couldn't access the py sequence
CSV
id,x,y,z,r,g,b
0,0.30778491,0.12740749,0.04903458,174.0,84.0,118.0
PYTHON
import bpy
import csv, os, bmesh, math
#filepaths
filepath = bpy.data.filepath
directory = os.path.dirname(filepath)
blendname = bpy.path.basename(bpy.data.filepath)
blendname = os.path.splitext(blendname)[0]
if blendname:
bpy.context.scene.render.filepath = blendname
print(blendname)
some_dict = {}
# DO POINTS
csvpoints= directory+"/csv/3d-points.csv"
pointsReader = csv.reader(open(csvpoints, newline=''), delimiter=',')
#bpy.ops.object.mode_set(mode='EDIT')
obj = bpy.context.object
verts = []
edges = []
faces = []
for idx, row in enumerate(pointsReader):
#print(idx, row)
id = row[0]
print("id = "+ id)
x = row[1]
print("x = " + x)
y = row[2]
print("y = " + y)
z = row[3]
print("z = " + z)
vert = (x,y,z)
verts.append(vert)
#create mesh and object
mesh = bpy.data.meshes.new("wave")
object = bpy.data.objects.new("wave",mesh)
#create mesh from python data
mesh.from_pydata(verts,[],[])
mesh.update(calc_edges=True)
#set mesh location
object.location = bpy.context.scene.cursor_location
bpy.context.scene.objects.link(object)