I've learned that an object may contain multiple meshes. I want to export all vertices from all meshes. How do I iterate through them?
Also, is there a simple way to know in advance the total count? Other than doing 2 passes?
Blender Stack Exchange is a question and answer site for people who use Blender to create 3D graphics, animations, or games. It only takes a minute to sign up.Sign up to join this community
A mesh may consist of loose parts the following script will export all vertices and faces. The length is determined by pythons len() you would need to change the print statements to writing into a file.
Uncomment the dump method
# dump(obj.data) to find out more on available properties you're interested in.
If you need also to get the edges of the mesh you could have a look at Python script to determine XYZ of tip of cone.
import bpy def dump(obj, level=0): for attr in dir(obj): if hasattr( obj, "attr" ): print( "obj.%s = %s" % (attr, getattr(obj, attr))) else: print( attr ) #obj = bpy.data.objects["Cube"] # particular object by name obj = bpy.context.scene.objects.active # active object # dump(obj.data) mesh = obj.data print("# of vertices=%d" % len(mesh.vertices)) for vert in mesh.vertices: print( 'v %f %f %f\n' % (vert.co.x, vert.co.y, vert.co.z) ) print("# of faces=%d" % len(mesh.polygons)) for face in mesh.polygons: print('face') #dump(face) for vert in face.vertices: print(vert)
# of vertices=8 v 1.000000 1.000000 -1.000000 v 1.000000 -1.000000 -1.000000 v -1.000000 -1.000000 -1.000000 v -1.000000 1.000000 -1.000000 v 1.000000 0.999999 1.000000 v 0.999999 -1.000001 1.000000 v -1.000000 -1.000000 1.000000 v -1.000000 1.000000 1.000000 # of faces=6 face 0 1 2 3 face 4 7 6 5 face 0 4 5 1 face 1 5 6 2 face 2 6 7 3 face 4 0 3 7