Skip to content

Instantly share code, notes, and snippets.

@zeffii
Created June 15, 2015 06:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zeffii/60836382c6760626db41 to your computer and use it in GitHub Desktop.
Save zeffii/60836382c6760626db41 to your computer and use it in GitHub Desktop.
import bpy
obj = bpy.context.active_object
mesh = obj.data
filepath_out = "/home/zeffii/Desktop/temp/single_line.obj"
with open(filepath_out, 'w') as ofile:
begin = "OBJ File: "
ofile.write(begin)
for v in mesh.vertices:
line = "{0} {1} "
v_sanitized = v.co.to_tuple(4) # precision 4
v_as_string = str(v_sanitized)[1:-1]
line = line.format("v", v_as_string).replace(",", "")
# print(line)
ofile.write(line)
for f in mesh.polygons:
line = "{0} {1} "
f_as_string = str(f.vertices[:])[1:-1]
line = line.format("f", f_as_string).replace(",", "")
# print(line)
ofile.write(line)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment