diff options
author | Remigiusz Fiedler <migius@gmx.net> | 2010-06-20 23:21:41 +0400 |
---|---|---|
committer | Remigiusz Fiedler <migius@gmx.net> | 2010-06-20 23:21:41 +0400 |
commit | 9927b361bd92fd3ca6f4f44270c36626de4c7d88 (patch) | |
tree | 0509708d7501a06f85224623885e478f08582cbb | |
parent | f0b048bf3c5aec68bc470f4214b6ee93bdde2c5b (diff) |
DXF-exporter script update: v1.36 - 2010.06.20 by migius
- added export Nurbs-Curve (3,4,5th-degree) into POLYLINE-NURBS(quad,cubic)
but no support for Bezier-Curves, because DXF doesnt support them
DXF-export library update: v1.34 - 2010.06.20 by migius
- bugfix POLYFACE
- added DXF-flags for POLYLINE and VERTEX class (NURBS-export)
-rw-r--r-- | release/scripts/bpymodules/dxfLibrary.py | 170 | ||||
-rw-r--r-- | release/scripts/export_dxf.py | 95 |
2 files changed, 177 insertions, 88 deletions
diff --git a/release/scripts/bpymodules/dxfLibrary.py b/release/scripts/bpymodules/dxfLibrary.py index ccd8ef9b625..41fe03a4bf4 100644 --- a/release/scripts/bpymodules/dxfLibrary.py +++ b/release/scripts/bpymodules/dxfLibrary.py @@ -1,6 +1,6 @@ #dxfLibrary.py : provides functions for generating DXF files # -------------------------------------------------------------------------- -__version__ = "v1.33 - 2009.06.16" +__version__ = "v1.34 - 2010.06.20" __author__ = "Stani Michiels(Stani), Remigiusz Fiedler(migius)" __license__ = "GPL" __url__ = "http://wiki.blender.org/index.php/Scripts/Manual/Export/autodesk_dxf" @@ -20,10 +20,15 @@ IDEAs: TODO: - add support for DXFr14 (needs extended file header) - add support for SPLINEs (possible first in DXFr14 version) +- add support for MTEXT - add user preset for floating point precision (3-16?) History -v1.33 - 2009.06.16 by migius +v1.34 - 2010.06.20 by migius + - bugfix POLYFACE + - added DXF-flags for POLYLINE and VERTEX class (NURBS-export) +v1.33 - 2009.07.03 by migius + - fix MTEXT newline bug (not supported by DXF-Exporter yet) - modif _point(): converts all coords to floats - modif LineType class: implement elements - added VPORT class, incl. defaults @@ -93,7 +98,6 @@ _HEADER_POINTS=['insbase','extmin','extmax'] #---helper functions----------------------------------- def _point(x,index=0): """Convert tuple to a dxf point""" - #print 'deb: _point=', x #------------- return '\n'.join([' %s\n%s'%((i+1)*10+index,float(x[i])) for i in range(len(x))]) def _points(plist): @@ -205,7 +209,7 @@ BY_STYLE = 5 #the flow direction is inherited from the associated text style AT_LEAST = 1 #taller characters will override EXACT = 2 #taller characters will not override -#---polyline flags +#---polyline flag 70 CLOSED =1 # This is a closed polyline (or a polygon mesh closed in the M direction) CURVE_FIT =2 # Curve-fit vertices have been added SPLINE_FIT =4 # Spline-fit vertices have been added @@ -215,6 +219,12 @@ CLOSED_N =32 # The polygon mesh is closed in the N direction POLYFACE_MESH =64 # The polyline is a polyface mesh CONTINOUS_LINETYPE_PATTERN =128 # The linetype pattern is generated continuously around the vertices of this polyline +#---polyline flag 75, = curve type +QUADRIC_NURBS = 5 +CUBIC_NURBS = 6 +BEZIER_CURVE = 8 + + #---text flags #horizontal LEFT = 0 @@ -269,7 +279,6 @@ class Face(_Entity): def __str__(self): out = ' 0\n3DFACE\n%s%s\n' %(self._common(),_points(self.points)) - #print 'deb:out=', out #------------------- return out #----------------------------------------------- @@ -318,34 +327,34 @@ class Line(_Entity): #----------------------------------------------- class PolyLine(_Entity): - def __init__(self,points,org_point=[0,0,0],flag=0,width=None,**common): + def __init__(self,points,org_point=[0,0,0],flag70=0,flag75=0,width=None,**common): #width = number, or width = list [width_start=None, width_end=None] - #for 2d-polyline: points = [ [x, y, z, width_start=None, width_end=None, bulge=0 or None], ...] - #for 3d-polyline: points = [ [x, y, z], ...] + #for 2d-polyline: points = [ [[x, y, z], vflag=None, [width_start=None, width_end=None], bulge=0 or None] ...] + #for 3d-polyline: points = [ [[x, y, z], vflag=None], ...] #for polyface: points = [points_list, faces_list] _Entity.__init__(self,**common) self.points=points self.org_point=org_point - self.flag=flag + self.pflag70 = flag70 + self.pflag75 = flag75 self.polyface = False self.polyline2d = False self.faces = [] # dummy value self.width= None # dummy value - if self.flag & POLYFACE_MESH: + if self.pflag70 & POLYFACE_MESH: self.polyface=True self.points=points[0] self.faces=points[1] self.p_count=len(self.points) self.f_count=len(self.faces) - elif not self.flag & POLYLINE_3D: + elif not (self.pflag70 & POLYLINE_3D): self.polyline2d = True if width: - if type(width)!='list': - width=[width,width] + if type(width)!='list': width=[width,width] self.width=width def __str__(self): - result= ' 0\nPOLYLINE\n%s 70\n%s\n' %(self._common(),self.flag) + result= ' 0\nPOLYLINE\n%s 70\n%s\n' %(self._common(),self.pflag70) result+=' 66\n1\n' result+='%s\n' %_point(self.org_point) if self.polyface: @@ -353,23 +362,32 @@ class PolyLine(_Entity): result+=' 72\n%s\n' %self.f_count elif self.polyline2d: if self.width!=None: result+=' 40\n%s\n 41\n%s\n' %(self.width[0],self.width[1]) + if self.pflag75: + result+=' 75\n%s\n' %self.pflag75 for point in self.points: result+=' 0\nVERTEX\n' result+=' 8\n%s\n' %self.layer if self.polyface: - result+='%s\n' %_point(point[0:3]) + result+='%s\n' %_point(point) result+=' 70\n192\n' elif self.polyline2d: - result+='%s\n' %_point(point[0:2]) - if len(point)>4: - width1, width2 = point[3], point[4] + result+='%s\n' %_point(point[0]) + flag = point[1] + if len(point)>2: + [width1, width2] = point[2] if width1!=None: result+=' 40\n%s\n' %width1 if width2!=None: result+=' 41\n%s\n' %width2 - if len(point)==6: - bulge = point[5] + if len(point)==4: + bulge = point[3] if bulge: result+=' 42\n%s\n' %bulge + if flag: + result+=' 70\n%s\n' %flag else: - result+='%s\n' %_point(point[0:3]) + result+='%s\n' %_point(point[0]) + flag = point[1] + if flag: + result+=' 70\n%s\n' %flag + for face in self.faces: result+=' 0\nVERTEX\n' result+=' 8\n%s\n' %self.layer @@ -456,7 +474,7 @@ class Mtext(Text): else:spacingWidth=self.height*self.spacingFactor for text in texts: while text: - result+='%s\n'%Text(text[:self.width], + result+='%s' %Text(text[:self.width], point=(self.point[0]+x*spacingWidth, self.point[1]+y*spacingWidth, self.point[2]), @@ -472,43 +490,46 @@ class Mtext(Text): #----------------------------------------------- ##class _Mtext(_Entity): -## """Mtext not functioning for minimal dxf.""" -## def __init__(self,text='',point=(0,0,0),attachment=1, -## charWidth=None,charHeight=1,direction=1,height=100,rotation=0, -## spacingStyle=None,spacingFactor=None,style=None,width=100, -## xdirection=None,**common): -## _Entity.__init__(self,**common) -## self.text=text -## self.point=point -## self.attachment=attachment -## self.charWidth=charWidth -## self.charHeight=charHeight -## self.direction=direction -## self.height=height -## self.rotation=rotation -## self.spacingStyle=spacingStyle -## self.spacingFactor=spacingFactor -## self.style=style -## self.width=width -## self.xdirection=xdirection -## def __str__(self): -## input=self.text -## text='' -## while len(input)>250: -## text+='3\n%s\n'%input[:250] -## input=input[250:] -## text+='1\n%s\n'%input -## result= '0\nMTEXT\n%s\n%s\n40\n%s\n41\n%s\n71\n%s\n72\n%s%s\n43\n%s\n50\n%s\n'%\ -## (self._common(),_point(self.point),self.charHeight,self.width, -## self.attachment,self.direction,text, -## self.height, -## self.rotation) -## if self.style:result+='7\n%s\n'%self.style -## if self.xdirection:result+='%s\n'%_point(self.xdirection,1) -## if self.charWidth:result+='42\n%s\n'%self.charWidth -## if self.spacingStyle:result+='73\n%s\n'%self.spacingStyle -## if self.spacingFactor:result+='44\n%s\n'%self.spacingFactor -## return result + """Mtext not functioning for minimal dxf.""" + """ + def __init__(self,text='',point=(0,0,0),attachment=1, + charWidth=None,charHeight=1,direction=1,height=100,rotation=0, + spacingStyle=None,spacingFactor=None,style=None,width=100, + xdirection=None,**common): + _Entity.__init__(self,**common) + self.text=text + self.point=point + self.attachment=attachment + self.charWidth=charWidth + self.charHeight=charHeight + self.direction=direction + self.height=height + self.rotation=rotation + self.spacingStyle=spacingStyle + self.spacingFactor=spacingFactor + self.style=style + self.width=width + self.xdirection=xdirection + def __str__(self): + input=self.text + text='' + while len(input)>250: + text+='3\n%s\n'%input[:250] + input=input[250:] + text+='1\n%s\n'%input + result= '0\nMTEXT\n%s\n%s\n40\n%s\n41\n%s\n71\n%s\n72\n%s%s\n43\n%s\n50\n%s\n'%\ + (self._common(),_point(self.point),self.charHeight,self.width, + self.attachment,self.direction,text, + self.height, + self.rotation) + if self.style:result+='7\n%s\n'%self.style + if self.xdirection:result+='%s\n'%_point(self.xdirection,1) + if self.charWidth:result+='42\n%s\n'%self.charWidth + if self.spacingStyle:result+='73\n%s\n'%self.spacingStyle + if self.spacingFactor:result+='44\n%s\n'%self.spacingFactor + return result + """ + #---tables --------------------------------------------------- #----------------------------------------------- @@ -591,11 +612,11 @@ class VPort(_Call): target=(0.0,0.0,0.0), height=1.0, ratio=1.0, - lens=50, - frontClipping=0, - backClipping=0, - snap_rotation=0, - twist=0, + lens=50.0, + frontClipping=0.0, + backClipping=0.0, + snap_rotation=0.0, + twist=0.0, mode=0, circle_zoom=100, fast_zoom=1, @@ -669,15 +690,15 @@ class VPort(_Call): #----------------------------------------------- class View(_Call): def __init__(self,name,flag=0, - width=1, - height=1, + width=1.0, + height=1.0, center=(0.5,0.5), - direction=(0,0,1), - target=(0,0,0), - lens=50, - frontClipping=0, - backClipping=0, - twist=0,mode=0 + direction=(0.0,0.0,1.0), + target=(0.0,0.0,0.0), + lens=50.0, + frontClipping=0.0, + backClipping=0.0, + twist=0.0,mode=0 ): self.name=name self.flag=flag @@ -836,11 +857,12 @@ class LineList(_Entity): self.closed=closed self.points=copy.copy(points) def __str__(self): - if self.closed:points=self.points+[self.points[0]] + if self.closed: + points=self.points+[self.points[0]] else: points=self.points result='' for i in range(len(points)-1): - result+= Line(points=[points[i],points[i+1]],parent=self) + result+= Line(points=[points[i][0],points[i+1][0]],parent=self) return result[1:] #----------------------------------------------------- diff --git a/release/scripts/export_dxf.py b/release/scripts/export_dxf.py index 17f2132fbe8..93204a18f8c 100644 --- a/release/scripts/export_dxf.py +++ b/release/scripts/export_dxf.py @@ -7,7 +7,7 @@ Tooltip: 'Export geometry to DXF/DWG-r12 (Drawing eXchange Format).' """ -__version__ = "1.35 - 2009.06.18" +__version__ = "1.36 - 2010.06.20" __author__ = "Remigiusz Fiedler (AKA migius)" __license__ = "GPL" __url__ = "http://wiki.blender.org/index.php/Scripts/Manual/Export/autodesk_dxf" @@ -46,6 +46,9 @@ TODO: - wip: fix support Include-Duplis, cause not conform with INSERT-method History +v1.36 - 2010.06.20 by migius +- added export Nurbs-Curve (3,4,5th-degree) into POLYLINE-NURBS(quad,cubic) + but no support for Bezier-Curves, because DXF doesnt support them v1.35 - 2009.06.18 by migius - export multiple-instances of Curve-Objects as BLOCK/INSERTs - added export Cameras (ortho and persp) to VPORTs, incl. clipping @@ -626,7 +629,10 @@ def writeMeshEntities(allpoints, edges, faces, **common): i+=1 allpoints = newverts faces = [[map[v]+1 for v in f] for f in faces] - dxfPOLYFACE = DXF.PolyLine([allpoints, faces], flag=64, **common) + flag70 = 64 + flag75 = 0 + #dxfPOLYFACE = DXF.PolyLine([allpoints, faces], flag=[64,0,0], **common) + dxfPOLYFACE = DXF.PolyLine([allpoints, faces], flag70=flag70, flag75=flag70, width=0.0, **common) #print '\n deb: dxfPOLYFACE=',dxfPOLYFACE #------------- entities.append(dxfPOLYFACE) elif '3DFACEs'==c: @@ -672,9 +678,9 @@ def curve_drawBlender(vertList, org_point=[0.0,0.0,0.0], closed=0, name="dxfCurv ob = Object.New("Curve",name) cu = Curve.New(name) #print 'deb: vertList=\n', vertList #--------- - curve = cu.appendNurb(BezTriple.New(vertList[0])) + curve = cu.appendNurb(BezTriple.New(vertList[0][0])) for p in vertList[1:]: - curve.append(BezTriple.New(p)) + curve.append(BezTriple.New(p[0])) for point in curve: #point.handleTypes = [VECT, VECT] point.handleTypes = [FREE, FREE] @@ -1088,27 +1094,81 @@ def writeCurveEntities(curve, mx, """help routine for exportCurve() """ entities = [] - + width1,width2 = None, None if 1: for cur in curve: #print 'deb: START cur=', cur #-------------- + #print 'deb: dir(curve):',dir(cur) #--------- + #print 'deb: curve.type:',cur.type #--------- points = [] - if cur.isNurb(): + flags = [] + pflag70, pflag75 = 0,0 + + if cur.type==4: # is NURBS + #if cur.isNurb(): + #print 'deb:isNurb --------------' #--------- + pflag70 = 4 + orderU = cur.orderU + # curve type: + # 0: curvNoFitted + # 5: curvQuadraticBspline + # 6: curvCubicBspline + # 8: curvBezier + if orderU<=4: pflag75 = 5 + elif orderU>=5: pflag75 = 6 + + vflag70 = 16 + i = -2 for point in cur: #print 'deb:isNurb point=', point #--------- + i+=1 + if i==orderU-1: i = 0 + if i: + flags.append([16, [width1,width2]]) + else: + flags.append([8, [width1,width2]]) vec = point[0:3] #print 'deb: vec=', vec #--------- pkt = Mathutils.Vector(vec) #print 'deb: pkt=', pkt #--------- points.append(pkt) - else: + if not cur.isCyclic(): + points = points[1:-1] + flags = flags[1:-1] + elif cur.type==1: # is Bezier + #print 'deb:isBezier --------------' #--------- + pflag75 = 8 + vflag70 = 1 for point in cur: + #print 'deb:isBezier point=', point #--------- #print 'deb:isBezier point=', point.getTriple() #--------- - vec = point.getTriple()[1] + ptan1,pfit,ptan2 = point.getTriple() + #print 'deb: point=', pt #--------- + ptan1 = Mathutils.Vector(ptan1) + pfit = Mathutils.Vector(pfit) + ptan2 = Mathutils.Vector(ptan2) + #print 'deb: pkt=', pkt #--------- + points.append(ptan1) + flags.append([2, [width1,width2]]) + points.append(pfit) + flags.append([1, [width1,width2]]) + points.append(ptan2) + flags.append([2, [width1,width2]]) + if not cur.isCyclic(): + points = points[1:-1] + flags = flags[1:-1] + elif cur.type==0: # is Polygon + #print 'deb:isPolygon --------------' #--------- + #pflag70 = 4 + pflag75 = 0 + for point in cur: + #print 'deb:isPoly point=', point #--------- + vec = point[0:3] #print 'deb: vec=', vec #--------- pkt = Mathutils.Vector(vec) #print 'deb: pkt=', pkt #--------- points.append(pkt) + flags.append([None, [width1,width2]]) #print 'deb: points', points #-------------- if len(points)>1: @@ -1131,7 +1191,12 @@ def writeCurveEntities(curve, mx, if cur.isCyclic(): closed = 1 else: closed = 0 points = toGlobalOrigin(points) - + points_temp = [] + for p,f in zip(points,flags): + points_temp.append([p,f[0],f[1]]) + points = points_temp + #print 'deb: points', points #-------------- + if DEBUG: curve_drawBlender(points,OCS_origin,closed) #deb: draw to scene common['extrusion']= Extrusion @@ -1140,6 +1205,7 @@ def writeCurveEntities(curve, mx, common['thickness']= Thickness #print 'deb: common=', common #------------------ + flag70, flag75 = pflag70+closed, pflag75 if 0: #DEBUG p=AXaxis[:3] entities.append(DXF.Line([[0,0,0], p],**common)) @@ -1149,14 +1215,14 @@ def writeCurveEntities(curve, mx, p=OCS_origin[:3] entities.append(DXF.Line([[0,0,0], p],**common)) #OCS_origin=[0,0,0] #only debug---------------- - dxfPLINE = DXF.PolyLine(points,OCS_origin,closed,**common) + dxfPLINE = DXF.PolyLine(points,OCS_origin, flag70=flag70, flag75=flag70, width=0.0,**common) entities.append(dxfPLINE) - dxfPLINE = DXF.PolyLine(points,OCS_origin,closed,**common) + dxfPLINE = DXF.PolyLine(points,OCS_origin, flag70=flag70, flag75=flag70, width=0.0,**common) entities.append(dxfPLINE) if Thickness: common['thickness']= -Thickness - dxfPLINE = DXF.PolyLine(points,OCS_origin,closed,**common) + dxfPLINE = DXF.PolyLine(points,OCS_origin, flag70=flag70, flag75=flag70, width=0.0,**common) entities.append(dxfPLINE) elif c=="LINEs": # export Curve as multiple LINEs @@ -1561,8 +1627,9 @@ def do_export(export_list, filepath): dxfLINE = DXF.Line(linepoints,paperspace=espace,color=LAYERCOLOR_DEF) entities.append(dxfLINE) else: - dxfPLINE = DXF.PolyLine(points,points[0],closed,\ - paperspace=espace, color=LAYERCOLOR_DEF) + fag70, flag75 = closed, 0 + dxfPOLYFACE = DXF.PolyLine([allpoints, faces], flag70=flag70, flag75=flag70, width=0.0, paperspace=espace, color=LAYERCOLOR_DEF) + #dxfPLINE = DXF.PolyLine(points,points[0],[closed,0,0], paperspace=espace, color=LAYERCOLOR_DEF) d.append(dxfPLINE) |