Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2007-05-02 07:33:49 +0400
committerCampbell Barton <ideasman42@gmail.com>2007-05-02 07:33:49 +0400
commit98bdbab495036cbd5b9a06d43b8ee40c80797c3c (patch)
tree722782c2b8e412982b3a778e3f290ebd65d18bc8 /release
parenta8756ba0137fd304c480d9cd76ee11aa2b94d09b (diff)
rewrote most of this script.
* Export edges instead of faces * dont export fgon edges * export all objects (not just active) including Dupli Objects and static particles * use PupBlock rather then a gui that uses a window. * write the file normaly rather then redirecting stdout
Diffstat (limited to 'release')
-rw-r--r--release/scripts/xfig_export.py462
1 files changed, 150 insertions, 312 deletions
diff --git a/release/scripts/xfig_export.py b/release/scripts/xfig_export.py
index 10fdb1396fe..e8e0c0ded0e 100644
--- a/release/scripts/xfig_export.py
+++ b/release/scripts/xfig_export.py
@@ -6,7 +6,7 @@ Group: 'Export'
Tooltip: 'Export selected mesh to xfig Format (.fig)'
"""
-__author__ = "Dino Ghilardi "
+__author__ = 'Dino Ghilardi', 'Campbell Barton AKA Ideasman42'
__url__ = ("blender", "elysiun")
__version__ = "1.1"
@@ -28,369 +28,207 @@ __bpydoc__ = """\
# 'Raw triangle export' (Anthony D'Agostino, http://www.redrival.com/scorpius)|
import Blender
-from Blender import Draw, BGL
-from Blender.Window import DrawProgressBar
+from Blender import Draw
+import BPyObject
#, meshtools
import sys
+import bpy
#import time
# =================================
# === Write xfig Format.===
# =================================
-#globals definition and init
-mystring = ''
-mymsg = ''
-toggle=0
-sel3files=0
-maxX=-1000000000
-maxY=-1000000000
-maxZ=-1000000000
-minX=minY=minZ=10000000000
-boolmode=0 #0= export in inches, 1= export in cm
-dimscale=float(1200) #scale due to the cm/inches select. default: inches
-hidden_flag=0
-
-space = float(2) #space between figures, in blender units.
-scale= float(1200) #conversion scale to xfig units.
-guiscale=float(1) #scale shown on the ruler in the GUI
-#return values from gui items, just to deallocate them on exit.
-guiret1=guiret2=guiret3=guiret4=guiret5=guiret6=guiret7=0
-
-ScalePopup=0
-DistancePopup=0
-SpacePopup=0
-#end of globals definition
-
-
-def getmaxmin(ob, mesh):
+def collect_edges(edges):
"""Gets the max-min coordinates of the mesh"""
- global maxX,maxY,maxZ,minX,minY,minZ
"""Getting the extremes of the mesh to be exported"""
maxX=maxY=maxZ = -1000000000
minX=minY=minZ = 1000000000
- for face in mesh.faces:
- for v in face:
- x,y,z = v.co
- maxX = max(maxX, x)
- maxY = max(maxY, y)
- maxZ = max(maxZ, z)
- minX = min(minX, x)
- minY = min(minY, y)
- minZ = min(minZ, z)
-
-def xfigheader():
- global export_type
- print '#FIG 3.2 Produced by xfig version 3.2.5-alpha5'
- print 'Landscape'
- print 'Center'
- if boolmode==0:
- print 'Inches'
- else:
- print 'Metric'
- #print export_type
- print 'Letter'
- print '100.00'
- print 'Single'
- print '-2'
- print '1200 2'
-
-def xytransform(face):
- """gives the face vertexes coordinates in the xfig format/translation (view xy)"""
- v4=None
- x4=y4=z4=None
- if len(face)==3:
- v1,v2,v3=face.v
- else:
- v1,v2,v3,v4=face.v
+ FGON= Blender.Mesh.EdgeFlags.FGON
- x1,y1,z1 = v1.co
- x2,y2,z2 = v2.co
- x3,y3,z3 = v3.co
- y1=-y1
- y2=-y2
- y3=-y3
- if v4:
- x4,y4,z4 = v4.co
- y4=-y4
- return x1,y1,z1,x2,y2,z2,x3,y3,z3,x4,y4,z4
-
-def xztransform(face):
- """gives the face vertexes coordinates in the xfig format/translation (view xz)"""
- v4=None
- x4=y4=z4=None
- if len(face)==3:
- v1,v2,v3=face.v
- else:
- v1,v2,v3,v4=face.v
-
- #Order vertexes
- x1,y1,z1 = v1.co
- x2,y2,z2 = v2.co
- x3,y3,z3 = v3.co
- y1=-y1
- y2=-y2
- y3=-y3
+ me = bpy.data.meshes.new()
+ for ob_base in bpy.data.scenes.active.objects.context:
+ for ob in BPyObject.getDerivedObjects(ob_base):
+ me.verts = None
+ try: me.getFromObject(ob[0])
+ except: pass
+
+ if me.edges:
+ me.transform(ob[1])
+
+ for ed in me.edges:
+ if not ed.flag & FGON:
+ x,y,z = v1 = tuple(ed.v1.co)
+ maxX = max(maxX, x)
+ maxY = max(maxY, y)
+ maxZ = max(maxZ, z)
+ minX = min(minX, x)
+ minY = min(minY, y)
+ minZ = min(minZ, z)
+
+ x,y,z = v2 = tuple(ed.v2.co)
+ maxX = max(maxX, x)
+ maxY = max(maxY, y)
+ maxZ = max(maxZ, z)
+ minX = min(minX, x)
+ minY = min(minY, y)
+ minZ = min(minZ, z)
+
+ edges.append( (v1, v2) )
+
+ me.verts = None # free memory
+ return maxX,maxY,maxZ,minX,minY,minZ
+
+def xfigheader(file):
+ file.write('#FIG 3.2 Produced by xfig version 3.2.5-alpha5\n')
+ file.write('Landscape\n')
+ file.write('Center\n')
+ file.write('Metric\n')
+ file.write('A4\n')
+ file.write('100.00\n')
+ file.write('Single\n')
+ file.write('-2\n')
+ file.write('1200 2\n')
+
+def figdata(file, edges, expview, bounds, scale, space):
+ maxX,maxY,maxZ,minX,minY,minZ = bounds
+
+ def xytransform(ed):
+ """gives the face vertexes coordinates in the xfig format/translation (view xy)"""
+ x1,y1,z1 = ed[0]
+ x2,y2,z2 = ed[1]
+ y1=-y1; y2=-y2
+ return x1,y1,z1,x2,y2,z2
+
+ def xztransform(ed):
+ """gives the face vertexes coordinates in the xfig format/translation (view xz)"""
+ x1,y1,z1 = ed[0]
+ x2,y2,z2 = ed[1]
+ y1=-y1
+ y2=-y2
+
+ z1=-z1+maxZ-minY +space
+ z2=-z2+maxZ-minY +space
+ return x1,y1,z1,x2,y2,z2
+
+ def yztransform(ed):
+ """gives the face vertexes coordinates in the xfig format/translation (view xz)"""
+ x1,y1,z1 = ed[0]
+ x2,y2,z2 = ed[1]
+ y1=-y1; y2=-y2
+ z1=-(z1-maxZ-maxX-space)
+ z2=-(z2-maxZ-maxX-space)
+ return x1,y1,z1,x2,y2,z2
+
+ def transform(ed, expview, scale):
+ if expview=='xy':
+ x1,y1,z1,x2,y2,z2 = xytransform(ed)
+ return int(x1*scale),int(y1*scale),int(x2*scale),int(y2*scale)
+ elif expview=='xz':
+ x1,y1,z1,x2,y2,z2 = xztransform(ed)
+ return int(x1*scale),int(z1*scale),int(x2*scale),int(z2*scale)
+ elif expview=='yz':
+ x1,y1,z1,x2,y2,z2 = yztransform(ed)
+ return int(z1*scale),int(y1*scale),int(z2*scale),int(y2*scale)
- z1=-z1+maxZ-minY +space
- z2=-z2+maxZ-minY +space
- z3=-z3+maxZ-minY +space
-
- if v4:
- x4,y4,z4 = v4.co
- y4=-y4
- z4=-z4+maxZ-minY +space
- return x1,y1,z1,x2,y2,z2,x3,y3,z3,x4,y4,z4
-
-def yztransform(face):
- """gives the face vertexes coordinates in the xfig format/translation (view xz)"""
- v4=None
- x4=y4=z4=None
- if len(face)==3:
- v1,v2,v3=face.v
- else:
- v1,v2,v3,v4=face.v
-
- #Order vertexes
- x1,y1,z1 = v1.co
- x2,y2,z2 = v2.co
- x3,y3,z3 = v3.co
- y1=-y1; y2=-y2; y3=-y3
- z1=-(z1-maxZ-maxX-space)
- z2=-(z2-maxZ-maxX-space)
- z3=-(z3-maxZ-maxX-space)
- if v4:
- x4,y4,z4 = v4.co
- y4=-y4
- z4=-(z4-maxZ-maxX-space)
- return x1,y1,z1,x2,y2,z2,x3,y3,z3,x4,y4,z4
-
-def figdata(ob, expview):
"""Prints all the xfig data (no header)"""
- mesh = ob.getData(mesh=1)
- facenumber = len(mesh.faces)
- for face in mesh.faces:
- if len(face) == 3: # triangle
- print '2 3 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 4'
- if expview=='xy':
- x1,y1,z1,x2,y2,z2,x3,y3,z3,x4,y4,z4=xytransform(face)
- faceverts = int(x1*scale),int(y1*scale),int(x2*scale),int(y2*scale),int(x3*scale),int(y3*scale), int(x1*scale),int(y1*scale)
- elif expview=='xz':
- x1,y1,z1,x2,y2,z2,x3,y3,z3,x4,y4,z4=xztransform(face)
- faceverts = int(x1*scale),int(z1*scale),int(x2*scale),int(z2*scale),int(x3*scale),int(z3*scale), int(x1*scale),int(z1*scale)
- elif expview=='yz':
- x1,y1,z1,x2,y2,z2,x3,y3,z3,x4,y4,z4=yztransform(face)
- faceverts = int(z1*scale),int(y1*scale),int(z2*scale),int(y2*scale),int(z3*scale),int(y3*scale),int(z1*scale),int(y1*scale)
- print '\t% i % i % i % i % i % i % i % i' % faceverts
- else: # Quad
- print '2 3 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5'
- if expview=='xy':
- x1,y1,z1,x2,y2,z2,x3,y3,z3,x4,y4,z4=xytransform(face)
- faceverts = int(x1*scale),int(y1*scale),int(x2*scale),int(y2*scale),int(x3*scale),int(y3*scale),int(x4*scale),int(y4*scale), int(x1*scale),int(y1*scale)
-
- elif expview=='xz':
- x1,y1,z1,x2,y2,z2,x3,y3,z3,x4,y4,z4=xztransform(face)
- faceverts = int(x1*scale),int(z1*scale),int(x2*scale),int(z2*scale),int(x3*scale),int(z3*scale),int(x4*scale),int(z4*scale), int(x1*scale),int(z1*scale)
-
- elif expview=='yz':
- x1,y1,z1,x2,y2,z2,x3,y3,z3,x4,y4,z4=yztransform(face)
- faceverts = int(z1*scale),int(y1*scale),int(z2*scale),int(y2*scale),int(z3*scale),int(y3*scale),int(z4*scale),int(y4*scale), int(z1*scale),int(y1*scale)
- print '\t% i % i % i % i % i % i % i % i % i % i' % faceverts
+ for ed in edges:
+ file.write('2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 2\n')
+ file.write('\t %i %i %i %i\n' % transform(ed, expview, scale))
-
-
-def writexy(ob, filename):
+def writexy(edges, bounds, filename, scale, space):
"""writes the x-y view file exported"""
- global maxX, maxY, maxZ
- global minX, minY, minZ
- global space
- global scale
- #start = time.clock()
+
file = open(filename, 'wb')
- std=sys.stdout
- sys.stdout=file
- xfigheader()
- figdata(ob, 'xy')# xydata()
- sys.stdout=std
- Blender.Window.DrawProgressBar(1.0, '') # clear progressbar
+ xfigheader(file)
+ figdata(file, edges, 'xy', bounds, scale, space)
file.close()
- #end = time.clock()
- #seconds = " in %.2f %s" % (end-start, "seconds")
print 'Successfully exported ', Blender.sys.basename(filename)# + seconds
-def writexz(filename):
+def writexz(edges, bounds, filename, scale, space):
"""writes the x-z view file exported"""
- global space,maxX,maxY,maxZ, scale
#start = time.clock()
file = open(filename, 'wb')
- std=sys.stdout
- sys.stdout=file
- xfigheader()
- figdata(ob, 'xz')#xzdata()
- sys.stdout=std
- Blender.Window.DrawProgressBar(1.0, '') # clear progressbar
+ xfigheader(file)
+ figdata(file, edges, 'xz', bounds, scale, space)
file.close()
- #end = time.clock()
- #seconds = " in %.2f %s" % (end-start, "seconds")
print 'Successfully exported ', Blender.sys.basename(filename)# + seconds
-def writeyz(filename):
+def writeyz(edges, bounds, filename, scale, space):
"""writes the y-z view file exported"""
- global maxX, maxY, maxZ, minX, minY, minZ,scale
+
#start = time.clock()
file = open(filename, 'wb')
-
- std=sys.stdout
- sys.stdout=file
-
- xfigheader()
- figdata(ob, 'yz')#yzdata()
- sys.stdout=std
- Blender.Window.DrawProgressBar(1.0, '') # clear progressbar
+ xfigheader(file)
+ figdata(file, edges, 'yz', bounds, scale, space)
file.close()
#end = time.clock()
#seconds = " in %.2f %s" % (end-start, "seconds")
print 'Successfully exported ', Blender.sys.basename(filename)# + seconds
-def writeall(ob, filename):
+def writeall(edges, bounds, filename, scale=450, space=2.0):
"""writes all 3 views
Every view is a combined object in the resulting xfig. file."""
- global maxX, maxY, maxZ, minX, minY, minZ,scale
- #start = time.clock()
+
+ maxX,maxY,maxZ,minX,minY,minZ = bounds
+
file = open(filename, 'wb')
- std=sys.stdout
- sys.stdout=file
-
- xfigheader()
- print '#upper view (7)'
- print '6 % i % i % i % i ', minX, minY, maxX, maxY
- figdata(ob, 'xy') #xydata()
- print '-6'
- print '#bottom view (1)'
- print '6 %i %i %i %i', minX, -minZ+maxZ-minY +space, maxX,-maxZ+maxZ-minY +space
- figdata(ob, 'xz') #xzdata()
- print '-6'
+ xfigheader(file)
+ file.write('#upper view (7)\n')
+ file.write('6 % i % i % i % i ')
+ file.write('%.6f %.6f %.6f %.6f\n' % (minX, minY, maxX, maxY))
+
+ figdata(file, edges, 'xy', bounds, scale, space)
+ file.write('-6\n')
+ file.write('#bottom view (1)\n')
+ file.write('6 %i %i %i %i ')
+ file.write('%.6f %.6f %.6f %.6f\n' % (minX, -minZ+maxZ-minY +space, maxX,-maxZ+maxZ-minY +space))
+
+ figdata(file, edges, 'xz', bounds, scale, space)
+ file.write('-6\n')
- print '#right view (3)'
- print '6 %i %i %i %i', minX, minZ-maxZ-maxX-space, maxX,maxZ-maxZ-maxX-space
- figdata(ob, 'yz') #yzdata()
- print '-6'
+ file.write('#right view (3)\n')
+ file.write('6 %i %i %i %i ')
+ file.write('%.6f %.6f %.6f %.6f\n' % (minX, -minZ+maxZ-minY +space, maxX,-maxZ+maxZ-minY +space))
+ figdata(file, edges, 'yz', bounds, scale, space)
+ file.write('-6\n')
- sys.stdout=std
- Blender.Window.DrawProgressBar(1.0, '') # clear progressbar
file.close()
- #end = time.clock()
- #seconds = " in %.2f %s" % (end-start, "seconds")
print 'Successfully exported ', Blender.sys.basename(filename)# + seconds
-
-#********************************************************USER INTERFACE*****************************************************
-#********************************************************USER INTERFACE*****************************************************
-#********************************************************USER INTERFACE*****************************************************
-def gui(): # the function to draw the screen
- global mystring, mymsg, toggle, sel3files, scale
- global guiret1, guiret2, guiret3, guiret4, guiret5, guiret6, guiret7
- global ScalePopup, SpacePopup, boolmode, guiscale,hidden_flag
- if len(mystring) > 90: mystring = ''
- # BGL.glClearColor(0,0,1,1)
- # BGL.glClear(BGL.GL_COLOR_BUFFER_BIT)
- BGL.glColor3f(1,1,1)
- guiret2=Draw.PushButton('Cancel', 2, 10, 10, 55, 20,'Cancel')
- guiret3=Draw.Toggle('1 file per view', 3, 10, 40, 110,20, sel3files, 'Export a file for each view')
- guiret4=Draw.PushButton('Export', 4, 70, 10, 70, 20, 'Select filename and export')
-
- ScalePopup=Draw.Number('Scale', 5, 10,70, 110,20, guiscale, 0.0001, 1000.1, 'Scaling factor')
- SpacePopup=Draw.Number('Space', 6, 10,90, 110,20, space, 0, 10000, 'Space between projections')
-
- guiret5=Draw.Toggle('cm', 7, 120,70, 40,20, boolmode, 'set scale to 1 blender unit = 1 cm in xfig')
- guiret6=Draw.Toggle('in', 8, 162,70, 40,20, not boolmode, 'set scale to 1 blender unit = 1 in in xfig')
-
- BGL.glRasterPos2i(72, 16)
- if toggle: toggle_state = 'down'
- else: toggle_state = 'up'
- #Draw.Text('The toggle button is %s.' % toggle_state, 'small')
- BGL.glRasterPos2i(10, 230)
- #Draw.Text('Type letters from a to z, ESC to leave.')
- BGL.glRasterPos2i(20, 200)
- Draw.Text(mystring)
- BGL.glColor3f(1,0.4,0.3)
- BGL.glRasterPos2i(340, 70)
- Draw.Text(mymsg, 'tiny')
-
-
-def event(evt, val): # the function to handle input events
- Draw.Redraw(1)
-
-import bpy
-
-def button_event(evt): # the function to handle Draw Button events
- global toggle, guiret5,scale, space, SpacePopup, boolmode, dimscale, guiscale
- global hidden_flag, sel3files
- if evt==1:
- toggle = 1 - toggle
- Draw.Redraw(1)
- if evt==2:
- Draw.Exit()
- return
- if evt==3:
- sel3files = 1-sel3files
- Draw.Redraw(1)
- if evt==4:
- try: ob = bpy.data.scenes.active.objects.active
- except: ob = None
- if not ob or ob.type != 'Mesh':
- BPyMessages.Error_NoMeshActive()
- return
-
- Blender.Window.FileSelector(fs_callback, 'Export fig', Blender.sys.makename(ext='.fig'))
- Draw.Exit()
- return
- if evt==5:
- guiscale = ScalePopup.val
- scale=dimscale*guiscale
- Draw.Redraw(1)
- if evt==6:
- space =SpacePopup.val
- if evt==7:
- boolmode=1
- dimscale=450 #converting to cm
- scale = dimscale*guiscale
- Draw.Redraw(1)
- if evt==8:
- boolmode=0
- dimscale = 1200
- scale = dimscale*guiscale
- Draw.Redraw(1)
- if evt==9:
- hidden_flag=1-hidden_flag
- Draw.Redraw(1)
-
-Draw.Register(gui, event, button_event) # registering the 3 callbacks
-
import BPyMessages
-def fs_callback(filename):
+
+def write_ui(filename):
if filename.lower().endswith('.fig'): filename = filename[:-4]
- try: ob = bpy.data.scenes.active.objects.active
- except: ob = None
- if not ob or ob.type != 'Mesh':
- BPyMessages.Error_NoMeshActive()
+ PREF_SEP= Draw.Create(0)
+ PREF_SCALE= Draw.Create(1200)
+ PREF_SPACE= Draw.Create(2.0)
+
+ block = [\
+ ("Separate Files", PREF_SEP, "Export each view axis as a seperate file"),\
+ ("Space: ", PREF_SPACE, 0.0, 10.0, "Space between views in blender units"),\
+ ("Scale: ", PREF_SCALE, 10, 100000, "Scale, 1200 is a good default")]
+
+ if not Draw.PupBlock("Export FIG", block):
return
- mesh = ob.getData(mesh=1)
- getmaxmin(ob, mesh)
+ edges = []
+ bounds = collect_edges(edges)
- if sel3files:
-
- writexy(ob, filename + '_XY.fig')
- writexz(ob, filename + '_XZ.fig')
- writeyz(ob, filename + '_YZ.fig')
- writeall(ob, filename + '.fig')
- print scale
- Draw.Exit()
+ if PREF_SEP.val:
+ writexy(edges, bounds, filename + '_XY.fig', PREF_SCALE.val, PREF_SPACE.val)
+ writexz(edges, bounds, filename + '_XZ.fig', PREF_SCALE.val, PREF_SPACE.val)
+ writeyz(edges, bounds, filename + '_YZ.fig', PREF_SCALE.val, PREF_SPACE.val)
+
+ writeall(edges, bounds, filename + '.fig', PREF_SCALE.val, PREF_SPACE.val)
+
+if __name__ == '__main__':
+ Blender.Window.FileSelector(write_ui, 'Export XFIG', Blender.sys.makename(ext='.fig'))
+ \ No newline at end of file