Faces and vertices lists?

How do i get a list with the faces in a mesh, and a list of vertices in each face?

Thank you!!

p.s. i’m looking throught several scripts, but the hierarchy it’s a bit confusing to me!

something like this should work:


import Blender
from Blender import *

ob = Object.GetSelected()[0]

obdata = ob.getData()

# total number of faces
totfaces = len(obdata.faces)
# total number of verts
totverts = len(obdata.verts)

# list with face indices
idx = []
for i in range(totfaces):
	idx.append(i)

# vertex coordinates
vco, vertidx = [], []
for i in idx:
	Ve,fvertidx = [], []

	fa = obdata.faces[i]

	for v in fa.v:

		Ve.append(v.co)
		fvertidx.append(v.index)


	vertidx.append(fvertidx)
	vco.append(Ve)

print vco
print ""
print vertidx

which returns the following for the default cube


[[[1.0000, 1.0000, -1.0000], [1.0000, -1.0000, -1.0000], [-1.0000, -1.0000, -1.0000], [-1.0000, 1.0000, -1.0000]], [[1.0000, 1.0000, 1.0000], [-1.0000, 1.0000, 1.0000], [-1.0000, -1.0000, 1.0000], [1.0000, -1.0000, 1.0000]], [[1.0000, 1.0000, -1.0000], [1.0000, 1.0000, 1.0000], [1.0000, -1.0000, 1.0000], [1.0000, -1.0000, -1.0000]], [[1.0000, -1.0000, -1.0000], [1.0000, -1.0000, 1.0000], [-1.0000, -1.0000, 1.0000], [-1.0000, -1.0000, -1.0000]], [[-1.0000, -1.0000, -1.0000], [-1.0000, -1.0000, 1.0000], [-1.0000, 1.0000, 1.0000], [-1.0000, 1.0000, -1.0000]], [[1.0000, 1.0000, 1.0000], [1.0000, 1.0000, -1.0000], [-1.0000, 1.0000, -1.0000], [-1.0000, 1.0000, 1.0000]]]

[[0, 1, 2, 3], [4, 7, 6, 5], [0, 4, 5, 1], [1, 5, 6, 2], [2, 6, 7, 3], [4, 0, 3, 7]]

The first list gives per face the coordinates of the vertices of that face and the second one gives the index of the verts per face

greetings,

wim

Thank you very, very, very much!!! :smiley: :smiley: