* Edited and consistent-ified the File->Import menu item labels and fileselect button...
[blender.git] / release / scripts / off_export.py
1 #!BPY
2
3 """
4 Name: 'Object File Format (.off)...'
5 Blender: 232
6 Group: 'Export'
7 Tooltip: 'Export selected mesh to Object File Format (*.off)'
8 """
9
10 # +---------------------------------------------------------+
11 # | Copyright (c) 2002 Anthony D'Agostino                   |
12 # | http://www.redrival.com/scorpius                        |
13 # | scorpius@netzero.com                                    |
14 # | February 3, 2001                                        |
15 # | Released under the Blender Artistic Licence (BAL)       |
16 # | Import Export Suite v0.5                                |
17 # +---------------------------------------------------------+
18 # | Read and write Object File Format (*.off)               |
19 # +---------------------------------------------------------+
20
21 import Blender, mod_meshtools
22 #import time
23
24 # ==============================
25 # ====== Write OFF Format ======
26 # ==============================
27 def write(filename):
28         #start = time.clock()
29         file = open(filename, "wb")
30
31         objects = Blender.Object.GetSelected()
32         objname = objects[0].name
33         meshname = objects[0].data.name
34         mesh = Blender.NMesh.GetRaw(meshname)
35         #mesh = Blender.NMesh.GetRawFromObject(meshname)        # for SubSurf
36         obj = Blender.Object.Get(objname)
37
38         # === OFF Header ===
39         file.write("OFF\n")
40         file.write("%d %d %d\n" % (len(mesh.verts), len(mesh.faces), 0))
41
42         # === Vertex List ===
43         for i in range(len(mesh.verts)):
44                 if not i%100 and mod_meshtools.show_progress:
45                         Blender.Window.DrawProgressBar(float(i)/len(mesh.verts), "Writing Verts")
46                 x, y, z = mesh.verts[i].co
47                 file.write("%f %f %f\n" % (x, y, z))
48
49         # === Face List ===
50         for i in range(len(mesh.faces)):
51                 if not i%100 and mod_meshtools.show_progress:
52                         Blender.Window.DrawProgressBar(float(i)/len(mesh.faces), "Writing Faces")
53                 file.write(`len(mesh.faces[i].v)`+' ')
54                 mesh.faces[i].v.reverse()
55                 for j in range(len(mesh.faces[i].v)):
56                         file.write(`mesh.faces[i].v[j].index`+' ')
57                 file.write("\n")
58
59
60         Blender.Window.DrawProgressBar(1.0, '')  # clear progressbar
61         file.close()
62         #end = time.clock()
63         #seconds = " in %.2f %s" % (end-start, "seconds")
64         message = "Successfully exported " + Blender.sys.basename(filename)# + seconds
65         mod_meshtools.print_boxed(message)
66
67 def fs_callback(filename):
68         if filename.find('.off', -4) <= 0: filename += '.off'
69         write(filename)
70
71 Blender.Window.FileSelector(fs_callback, "Export OFF")