Trying to export mesh info.

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

Post Reply
Posts: 3
Joined: Sun Nov 10, 2002 2:57 am

Trying to export mesh info.

Post by csDraco_ » Sun Nov 10, 2002 3:07 am

Hi there.
I'm trying to export a complete Mesh: Vertices, Faces, and UV-Coords using the 2.25 API with no luck :(

I can see within the documentation that the Face Object ...
contains all of that, but I've been dir()ing the Blender Module for hours with no luck at finding that object or any other that contains the information (Faces, Vertices, UV-coords).

Can someone please point me in the right direction, maby I'm just missing something obvious here.

Posts: 13
Joined: Mon Oct 28, 2002 9:48 am


Post by lisabeeren » Mon Nov 11, 2002 2:04 am

I know the feeling hey, I spent hours guessing how to do it :)

My script gets the first object selected;

selectedObjects = Blender.Object.getSelected()
currentObject = selectedObjects[0]
#assumes it's a mesh
mesh =
faces = mesh.faces
for face in faces
#body of loop


in the loop you can do face[0] to get the first point of the face, face[1] etc. whether you can get face[2]or[3] depends on if it's a triangle, quad etc.
point = face[0]
then you can call
point [0] # 0 through 2, to get the xyz of that point.

alternatively, face[0][0] gives you the X coordinate of the 1st face.

I don't feel that communicating clearly is one of my fortes, so I hope you can make sense.

Also, I wonder if this isn't the kind of question that should be on rather than dunno.

But the fact that the documentation is appaling should probably be brought up here.


Posts: 3
Joined: Sun Nov 10, 2002 2:57 am

Post by csDraco_ » Thu Nov 14, 2002 4:15 am

Thanks for your reply lisabeeren!

I wish I knew about the ".faces" sooner .. I couldn't find that in the 2.25API, maby I just missed it.

The code is quite simple .. its that API ... arrr!
I found that it's easier to download the source code for Blender and look through a definintion of a module to see what it stores .. at least that seems to be upto date :)

Anyway thanks for your positive attitude, I think I was just about to give up at that point.

And now I have my export script almoust done :)
Here is the main part:

Code: Select all

objects = Blender.Object.GetSelected()
object = objects[0] # this better be a mesh :)
data =
faces = data.faces

string = "Mesh Data\n{"

faceNumber = 0
for face in faces:
	string += "\n  Face" + str(faceNumber) + "\n  {"

	vertexNumber = 0
	for vertex in face:
		vertexNumber += 1
		string += "\n    Vertex" + str(vertexNumber) + "\n    {"
		string += "\n      coordinates("
		string +=       str([0])
		string += ", " + str([1])
		string += ", " + str([2])
		string += ")"
		string += "\n      normal coordinates("
		string +=       str([0])
		string += ", " + str([1])
		string += ", " + str([2])
		string += ")"
		string += "\n      texture coordinates("
		string +=       str(vertex.uvco[0])
		string += ", " + str(vertex.uvco[1])
		string += ")"
		string += "\n    } // end of Vertex"

	string += "\n  } // end of face"
string += "\n} // end of Mesh"
print string

By the way ... I'm running into a problem with the uv coordinates, they simply never seem to change from their initial value of 0.0. I'v used uv maping on all faces of my object, and yet all of those uv coords. are still zeroes ... why?

Posts: 3
Joined: Sun Nov 10, 2002 2:57 am

Post by csDraco_ » Sat Nov 16, 2002 2:48 pm

I finally got the answer from, thank you once again eeshlo (Moderator)!

here is the reply I got concerning the uv coordinates
It probably is very confusing but 'uvco' are the 'sticky' coordinates (camera projection coordinates when using 'Make Sticky' in edit buttons), not the texture uv-coordinates. You need uv from the faces themselves:
and here is the modified code

Code: Select all

for uv in face.uv:
      string += "\n      texture coordinates("
      string +=   str(uv[0])
      string += ", " + str(uv[1]) 
I hope this helps someone else as well :)

Post Reply