trying to create a bmesh from csv coordinate list 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 &lt;module&gt;
  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)
The manuals suggest using the csvreader in a with block.

You made two mistakes.


You have to skip the first csv line, since it doesn't hold any values. (Or treat it differently.)
You have to parse the numeric values. float(row[0])




Working example.

import bpy
import csv, os, bmesh, math

#filepaths
filepath = bpy.data.filepath
directory = os.path.dirname(filepath)

verts = []
edges = []
faces = []

csvpoints= directory+"/points.csv"
pointsReader = csv.reader(open(csvpoints, newline=''), delimiter=',')   

with open(csvpoints, 'rt', encoding="utf8") as csvfile:
    pointsReader = csv.reader(csvfile, delimiter=',', quotechar='|')
    for idx, row in enumerate(pointsReader):
        if (idx &gt; 0):
            vert = (float(row[0]), float(row[1]), float(row[2])) 
            verts.append(vert)

obj = bpy.context.object

#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)