How can I connect a set of vertices to make a 3D model, with a script? [closed]

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?

• very related: blender.stackexchange.com/questions/2407/… May 19 '15 at 20:35
• Is the desired result a line or a mesh? May 19 '15 at 22:36
• A simple python script should do the trick. I'm not qualified to provide a good answer of how though. But it is possible. May 19 '15 at 22:49
• you should have more info ( rather than the verts list ), there are many possibilities in 3d , you can try Convex Hull function in blender ( search in space-bar menu ) May 19 '15 at 22:54
• You could write a VBA program to create an .obj file and import it into Blender. Then you could select verticies individually and fill the faces you needed. I was thinking about this today. Perhaps a python program that would somehow join all certified in the same plane while checking for duplicates? Thanks for the idea of exporting .objs from Excel! Jun 3 '15 at 2:24

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 circle.csv

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:
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