3
Name: 'xfig export (.fig)'
6
Tooltip: 'Export selected mesh to xfig Format (.fig)'
9
__author__ = 'Dino Ghilardi', 'Campbell Barton AKA Ideasman42'
10
__url__ = ("blender", "blenderartists.org")
14
This script exports the selected mesh to xfig (www.xfig.org) file format (i.e.: .fig)
16
The starting point of this script was Anthony D'Agostino's raw triangle format export.
17
(some code is still here and there, cut'n pasted from his script)
20
Select the mesh to be exported and run this script from "File->Export" menu.
21
The toggle button 'export 3 files' enables the generation of 4 files: one global
22
and three with the three different views of the object.
23
This script is licensed under the GPL license. (c) Dino Ghilardi, 2005
27
# .fig export, mostly brutally cut-n pasted from the
28
# 'Raw triangle export' (Anthony D'Agostino, http://www.redrival.com/scorpius)|
31
from Blender import Draw
38
# =================================
39
# === Write xfig Format.===
40
# =================================
42
def collect_edges(edges):
43
"""Gets the max-min coordinates of the mesh"""
45
"""Getting the extremes of the mesh to be exported"""
47
maxX=maxY=maxZ = -1000000000
48
minX=minY=minZ = 1000000000
50
FGON= Blender.Mesh.EdgeFlags.FGON
52
me = bpy.data.meshes.new()
53
for ob_base in bpy.data.scenes.active.objects.context:
54
for ob in BPyObject.getDerivedObjects(ob_base):
56
try: me.getFromObject(ob[0])
63
if not ed.flag & FGON:
64
x,y,z = v1 = tuple(ed.v1.co)
72
x,y,z = v2 = tuple(ed.v2.co)
80
edges.append( (v1, v2) )
82
me.verts = None # free memory
83
return maxX,maxY,maxZ,minX,minY,minZ
86
file.write('#FIG 3.2 Produced by xfig version 3.2.5-alpha5\n')
87
file.write('Landscape\n')
88
file.write('Center\n')
89
file.write('Metric\n')
91
file.write('100.00\n')
92
file.write('Single\n')
94
file.write('1200 2\n')
96
def figdata(file, edges, expview, bounds, scale, space):
97
maxX,maxY,maxZ,minX,minY,minZ = bounds
100
"""gives the face vertexes coordinates in the xfig format/translation (view xy)"""
104
return x1,y1,z1,x2,y2,z2
107
"""gives the face vertexes coordinates in the xfig format/translation (view xz)"""
113
z1=-z1+maxZ-minY +space
114
z2=-z2+maxZ-minY +space
115
return x1,y1,z1,x2,y2,z2
118
"""gives the face vertexes coordinates in the xfig format/translation (view xz)"""
122
z1=-(z1-maxZ-maxX-space)
123
z2=-(z2-maxZ-maxX-space)
124
return x1,y1,z1,x2,y2,z2
126
def transform(ed, expview, scale):
128
x1,y1,z1,x2,y2,z2 = xytransform(ed)
129
return int(x1*scale),int(y1*scale),int(x2*scale),int(y2*scale)
131
x1,y1,z1,x2,y2,z2 = xztransform(ed)
132
return int(x1*scale),int(z1*scale),int(x2*scale),int(z2*scale)
134
x1,y1,z1,x2,y2,z2 = yztransform(ed)
135
return int(z1*scale),int(y1*scale),int(z2*scale),int(y2*scale)
138
"""Prints all the xfig data (no header)"""
140
file.write('2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 2\n')
141
file.write('\t %i %i %i %i\n' % transform(ed, expview, scale))
143
def writexy(edges, bounds, filename, scale, space):
144
"""writes the x-y view file exported"""
146
file = open(filename, 'wb')
148
figdata(file, edges, 'xy', bounds, scale, space)
150
print 'Successfully exported ', Blender.sys.basename(filename)# + seconds
152
def writexz(edges, bounds, filename, scale, space):
153
"""writes the x-z view file exported"""
154
#start = time.clock()
155
file = open(filename, 'wb')
157
figdata(file, edges, 'xz', bounds, scale, space)
159
print 'Successfully exported ', Blender.sys.basename(filename)# + seconds
161
def writeyz(edges, bounds, filename, scale, space):
162
"""writes the y-z view file exported"""
164
#start = time.clock()
165
file = open(filename, 'wb')
167
figdata(file, edges, 'yz', bounds, scale, space)
170
#seconds = " in %.2f %s" % (end-start, "seconds")
171
print 'Successfully exported ', Blender.sys.basename(filename)# + seconds
173
def writeall(edges, bounds, filename, scale=450, space=2.0):
174
"""writes all 3 views
176
Every view is a combined object in the resulting xfig. file."""
178
maxX,maxY,maxZ,minX,minY,minZ = bounds
180
file = open(filename, 'wb')
183
file.write('#upper view (7)\n')
184
file.write('6 % i % i % i % i ')
185
file.write('%.6f %.6f %.6f %.6f\n' % (minX, minY, maxX, maxY))
187
figdata(file, edges, 'xy', bounds, scale, space)
189
file.write('#bottom view (1)\n')
190
file.write('6 %i %i %i %i ')
191
file.write('%.6f %.6f %.6f %.6f\n' % (minX, -minZ+maxZ-minY +space, maxX,-maxZ+maxZ-minY +space))
193
figdata(file, edges, 'xz', bounds, scale, space)
196
file.write('#right view (3)\n')
197
file.write('6 %i %i %i %i ')
198
file.write('%.6f %.6f %.6f %.6f\n' % (minX, -minZ+maxZ-minY +space, maxX,-maxZ+maxZ-minY +space))
199
figdata(file, edges, 'yz', bounds, scale, space)
203
print 'Successfully exported ', Blender.sys.basename(filename)# + seconds
207
def write_ui(filename):
208
if filename.lower().endswith('.fig'): filename = filename[:-4]
210
PREF_SEP= Draw.Create(0)
211
PREF_SCALE= Draw.Create(1200)
212
PREF_SPACE= Draw.Create(2.0)
215
("Separate Files", PREF_SEP, "Export each view axis as a seperate file"),\
216
("Space: ", PREF_SPACE, 0.0, 10.0, "Space between views in blender units"),\
217
("Scale: ", PREF_SCALE, 10, 100000, "Scale, 1200 is a good default")]
219
if not Draw.PupBlock("Export FIG", block):
223
bounds = collect_edges(edges)
226
writexy(edges, bounds, filename + '_XY.fig', PREF_SCALE.val, PREF_SPACE.val)
227
writexz(edges, bounds, filename + '_XZ.fig', PREF_SCALE.val, PREF_SPACE.val)
228
writeyz(edges, bounds, filename + '_YZ.fig', PREF_SCALE.val, PREF_SPACE.val)
230
writeall(edges, bounds, filename + '.fig', PREF_SCALE.val, PREF_SPACE.val)
232
if __name__ == '__main__':
233
Blender.Window.FileSelector(write_ui, 'Export XFIG', Blender.sys.makename(ext='.fig'))
b'\\ No newline at end of file'