I have a set of vertices in an spreadsheet from which I want to make an object. I only need it to connect the vertices and then fill in the faces. How can I do this in Blender?
The easiest path here is to export from excel as a
.csv (comma separated values) in a column-format that the existing .csv readers/importers written for Blender understand. Here's an example of one such addon . This means you don't have to write any import code.
But if you did want some autonomy over the import code, you might write something like this (but use a .csv format it is much easier to parse):
your csv, let's call it
x,y,z 0.000000,1.000000,0 0.500000,0.866025,0 0.866025,0.500000,0 1.000000,0.000000,0 0.866025,-0.500000,0 0.500000,-0.866025,0 0.000000,-1.000000,0 -0.500000,-0.866025,0 -0.866025,-0.500000,0 -1.000000,-0.000000,0 -0.866025,0.500000,0 -0.500000,0.866025,0
The least amount of code needed to read a file like that into blender might look something like this. You run from Text Editor, (but remember to get the path to the file correct first..)
import csv import os import bpy filename = 'circle.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: ofile = csv.reader(csvfile, delimiter=',') next(ofile) # <-- skip the x,y,z header # this makes a generator of the remaining non-empty lines rows = (r for r in ofile if r) # this converts the string representation of each line # to an x,y,z list, and stores it in the verts list. verts = [[float(i) for i in r] for r in rows] if verts: # join vertices into one uninterrupted chain of edges. edges = [[i, i+1] for i in range(len(verts)-1)] mesh = bpy.data.meshes.new("mesh_name") mesh.from_pydata(verts, edges, faces=) mesh.update() obj = bpy.data.objects.new("obj_name", mesh) scene = bpy.context.scene scene.objects.link(obj)