5

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?

someonewithpc
  • 12,381
  • 6
  • 55
  • 89
Ankur
  • 53
  • 1
  • 5
  • 1
    very related: http://blender.stackexchange.com/questions/2407/how-to-create-a-mesh-programmatically-without-bmesh/2416#2416 – zeffii May 19 '15 at 20:35
  • Is the desired result a line or a mesh? – atomicbezierslinger May 19 '15 at 22:36
  • 1
    A simple python script should do the trick. I'm not qualified to provide a good answer of how though. But it is possible. – Johnson Martin May 19 '15 at 22:49
  • 1
    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 ) – Chebhou 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! – Rick Henderson Jun 03 '15 at 02:24
  • related: http://blender.stackexchange.com/a/27592/3710 – p2or Jun 04 '15 at 13:02

1 Answers1

6

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)
zeffii
  • 39,634
  • 9
  • 103
  • 186
  • 2
    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. – Mutant Bob Jun 03 '15 at 19:31