5
$\begingroup$

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?

$\endgroup$
6
  • 1
    $\begingroup$ very related: blender.stackexchange.com/questions/2407/… $\endgroup$
    – zeffii
    May 19, 2015 at 20:35
  • $\begingroup$ Is the desired result a line or a mesh? $\endgroup$ May 19, 2015 at 22:36
  • 1
    $\begingroup$ A simple python script should do the trick. I'm not qualified to provide a good answer of how though. But it is possible. $\endgroup$ May 19, 2015 at 22:49
  • 1
    $\begingroup$ 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 ) $\endgroup$
    – Chebhou
    May 19, 2015 at 22:54
  • $\begingroup$ 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! $\endgroup$ Jun 3, 2015 at 2:24

1 Answer 1

6
$\begingroup$

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:
    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)
$\endgroup$
1
  • 2
    $\begingroup$ The one adjustment I would make is edges = [ [i,i+1] for i in range( len(verts)-1) ] which would create edges stringing all the vertices together. $\endgroup$
    – Mutant Bob
    Jun 3, 2015 at 19:31

Not the answer you're looking for? Browse other questions tagged .