I have 24 points which correspond to 12 different "elements" (2 points per element) saved in an .csv file with the following column order (1: Element Name, 2: x, 3: y, 4: z). I would like to import them so that there will be an edge between the two points for every element. Alternatively if this is not possible. It would be great to import all the points as separate elements. So I can know which points correspond to which element by the order of import.
This is great and I would like to extend this to the first six point: I tried to update your code with the edges I want, but it fails.
What does ensure_lookup_table() do ?
In if row there is only one vert. How can I add more ? The Ideal solution would be select 1,6 or all verts and make a mesh. The order of the edges would be cool to have but if too much hustle. Just importing 1, 6 or all verts and connecting them to a mesh would good.
Here my attempt to updated your code:
import bpy import bmesh import csv from mathutils import Vector from bpy_extras.object_utils import object_data_add csvfile = open('path2csvfile') inFile = csv.reader(csvfile, delimiter=',', quotechar='"') # skip header inFile.__next__() for row in inFile: # column order (0: Element Name, 1: x, 2: y, 3: z) if row not in bpy.data.objects: vert = [Vector((float(row),float(row),float(row)))] mesh = bpy.data.meshes.new(name=row) mesh.from_pydata(vert, , ) object_data_add(bpy.context, mesh) else: bpy.data.objects[row].select = True bpy.context.scene.objects.active = bpy.data.objects[row] bpy.ops.object.mode_set(mode='EDIT') mesh = bmesh.from_edit_mesh(bpy.data.objects[row].data) mesh.verts.new((float(row),float(row),float(row))) mesh.verts.ensure_lookup_table() mesh.edges.new([mesh.verts,mesh.verts]) mesh.edges.new([mesh.verts,mesh.verts]) mesh.edges.new([mesh.verts,mesh.verts]) mesh.edges.new([mesh.verts,mesh.verts]) mesh.edges.new([mesh.verts,mesh.verts]) bmesh.update_edit_mesh(bpy.data.objects[row].data, True) bpy.ops.object.mode_set(mode='OBJECT')