Featured post

new redirect for blender.org bpy docs.

http://www.blender.org/api/blender_python_api_current/ As of 10/11 november 2015 we can now link to the current api docs and not be worr...

July 05, 2011

printing verts and faces of object to a text file

import bpy
import os
main_path = os.getcwd()
print("writing to: " + main_path + "\n\n")
outputfile = os.path.join(main_path, 'filename_mine.txt')
with open(outputfile, 'w') as w_file:
# verts
w_file.write("verts=[\n")
print("verts=[\n")
for i in bpy.context.active_object.data.vertices:
print(i.co,",")
coords = i.co.x, i.co.y, i.co.z
w_file.write(str(coords)+",\n")
print("]")
w_file.write("]\n\n\n\n")
# faces
w_file.write("faces=[\n")
print("faces=[\n")
for i in bpy.context.active_object.data.polygons:
verts_on_face = i.vertices[:]
print(verts_on_face)
w_file.write(str(verts_on_face)+",\n")
print("]")
w_file.write("]\n\n\n\n")
view raw write_file.py hosted with ❤ by GitHub