Join vertices with faces

Hi,

i want to write a simple script, which creates a cube with a for loop.
There’s no problem to create the vertices, but i have a problem to join the vertices with faces.
How can I calculate the formula [?] for the face creation?

That’s what I have:

import Blender
from Blender import NMesh
import math
from math import*

me=NMesh.GetRaw()

totalvert=8

n=totalvert**(1/3.0)

for i in range(0,n,1):
	for j in range(0,n,1):
		for k in range(0,n,1):
			v=NMesh.Vert(j,i,k)
			me.verts.append(v)

n0=int(n)

for i in range(0,n,1):
	for j in range(0,n,1):
		f=NMesh.Face()
		f.v.append(me.verts[?])
		f.v.append(me.verts[?])
		f.v.append(me.verts[?])
		f.v.append(me.verts[?])
		me.faces.append(f)

NMesh.PutRaw(me,"plane",1)
Blender.Redraw()

Hello josi20

For a simple qube with 8 verts
the esiest is to simply do it by hand.
something like:

f=NMesh.Face()
f.v.append(me.verts[0])
f.v.append(me.verts[1])
f.v.append(me.verts[2])
f.v.append(me.verts[3])
me.faces.append(f)
f=NMesh.Face()
f.v.append(me.verts[0]) #the funny order is to keep the verts clockwise
f.v.append(me.verts[1]) #not sure if it is nessesarry. It may prevent
f.v.append(me.verts[5]) # problems with normals pointing inward
f.v.append(me.verts[4])
me.faces.append(f)
etc.

if there is a good formula id love to know
cheers Smitje

The cheater’s way to do it:

Get JMS’ great little script and save as
“mod_form_elem.py”. Get it here:
http://jmsoler.free.fr/didacticiel/blender/tutor/cpl_modelmshapes.htm.py

For your python code, type in these six lines:


import Blender
from Blender import *

import mod_form_elem
reload(mod_form_elem)
from mod_form_elem import *

cube=box('test9',[0.0,0.0,0.0],[5.0,5.0,5.0]) 

“[0.0,0.0,0.0]” is the location of the box
“[5.0,5.0,5.0]” are the dimensions of the box (it doesn’t have to be a cube).