diff --git a/release/scripts/bpymodules/dxfLibrary.py b/release/scripts/bpymodules/dxfLibrary.py index 67528f778e0..ccd8ef9b625 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.32 - 2009.06.06" +__version__ = "v1.33 - 2009.06.16" __author__ = "Stani Michiels(Stani), Remigiusz Fiedler(migius)" __license__ = "GPL" __url__ = "http://wiki.blender.org/index.php/Scripts/Manual/Export/autodesk_dxf" @@ -20,8 +20,14 @@ IDEAs: TODO: - add support for DXFr14 (needs extended file header) - add support for SPLINEs (possible first in DXFr14 version) +- add user preset for floating point precision (3-16?) History +v1.33 - 2009.06.16 by migius + - modif _point(): converts all coords to floats + - modif LineType class: implement elements + - added VPORT class, incl. defaults + - fix Insert class v1.32 - 2009.06.06 by migius - modif Style class: changed defaults to widthFactor=1.0, obliqueAngle=0.0 - modif Text class: alignment parameter reactivated @@ -88,7 +94,7 @@ _HEADER_POINTS=['insbase','extmin','extmax'] 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,x[i]) for i in range(len(x))]) + return '\n'.join([' %s\n%s'%((i+1)*10+index,float(x[i])) for i in range(len(x))]) def _points(plist): """Convert a list of tuples to dxf points""" @@ -137,8 +143,8 @@ class _Entity(_Call): if parent.layer!=None: result+=' 8\n%s\n'%parent.layer if parent.color!=None: result+=' 62\n%s\n'%parent.color if parent.lineType!=None: result+=' 6\n%s\n'%parent.lineType - #TODO: if parent.lineWeight!=None: result+='370\n%s\n'%parent.lineWeight - #TODO: if parent.visible!=None: result+='60\n%s\n'%parent.visible + # TODO: if parent.lineWeight!=None: result+='370\n%s\n'%parent.lineWeight + # TODO: if parent.visible!=None: result+='60\n%s\n'%parent.visible if parent.lineTypeScale!=None: result+=' 48\n%s\n'%parent.lineTypeScale if parent.elevation!=None: result+=' 38\n%s\n'%parent.elevation if parent.thickness!=None: result+=' 39\n%s\n'%parent.thickness @@ -287,7 +293,7 @@ class Insert(_Entity): self.rotation=rotation def __str__(self): - result=' 0\nINSERT\n 2\n%s\n%s\n%s\n'%\ + result=' 0\nINSERT\n 2\n%s\n%s%s\n'%\ (self.name,self._common(),_point(self.point)) if self.xscale!=None:result+=' 41\n%s\n'%self.xscale if self.yscale!=None:result+=' 42\n%s\n'%self.yscale @@ -383,7 +389,7 @@ class Point(_Entity): def __init__(self,points=None,**common): _Entity.__init__(self,**common) self.points=points - def __str__(self): #TODO: + def __str__(self): # TODO: return ' 0\nPOINT\n%s%s\n' %(self._common(), _points(self.points) ) @@ -515,7 +521,7 @@ class Block(_Collection): self.name=name self.flag=0 self.base=base - def __str__(self): #TODO: + def __str__(self): # TODO: e=''.join([str(x)for x in self.entities]) return ' 0\nBLOCK\n 8\n%s\n 2\n%s\n 70\n%s\n%s\n 3\n%s\n%s 0\nENDBLK\n'%\ (self.layer,self.name.upper(),self.flag,_point(self.base),self.name.upper(),e) @@ -535,15 +541,22 @@ class Layer(_Call): #----------------------------------------------- class LineType(_Call): """Custom linetype""" - def __init__(self,name='continuous',description='Solid line',elements=[],flag=64): - # TODO: Implement lineType elements + def __init__(self,name='CONTINUOUS',description='Solid line',elements=[0.0],flag=0): self.name=name self.description=description self.elements=copy.copy(elements) self.flag=flag def __str__(self): - return ' 0\nLTYPE\n 2\n%s\n 70\n%s\n 3\n%s\n 72\n65\n 73\n%s\n 40\n0.0\n'%\ - (self.name.upper(),self.flag,self.description,len(self.elements)) + result = ' 0\nLTYPE\n 2\n%s\n 70\n%s\n 3\n%s\n 72\n65\n'%\ + (self.name.upper(),self.flag,self.description) + if self.elements: + elements = ' 73\n%s\n' %(len(self.elements)-1) + elements += ' 40\n%s\n' %(self.elements[0]) + for e in self.elements[1:]: + elements += ' 49\n%s\n' %e + result += elements + return result + #----------------------------------------------- class Style(_Call): @@ -566,27 +579,137 @@ class Style(_Call): self.font.upper(),self.bigFont.upper()) #----------------------------------------------- -class View(_Call): - def __init__(self,name,flag=0,width=1,height=1,center=(0.5,0.5), - direction=(0,0,1),target=(0,0,0),lens=50, - frontClipping=0,backClipping=0,twist=0,mode=0): +class VPort(_Call): + def __init__(self,name,flag=0, + leftBottom=(0.0,0.0), + rightTop=(1.0,1.0), + center=(0.5,0.5), + snap_base=(0.0,0.0), + snap_spacing=(0.1,0.1), + grid_spacing=(0.1,0.1), + direction=(0.0,0.0,1.0), + target=(0.0,0.0,0.0), + height=1.0, + ratio=1.0, + lens=50, + frontClipping=0, + backClipping=0, + snap_rotation=0, + twist=0, + mode=0, + circle_zoom=100, + fast_zoom=1, + ucsicon=1, + snap_on=0, + grid_on=0, + snap_style=0, + snap_isopair=0 + ): self.name=name self.flag=flag - self.width=width - self.height=height + self.leftBottom=leftBottom + self.rightTop=rightTop + self.center=center + self.snap_base=snap_base + self.snap_spacing=snap_spacing + self.grid_spacing=grid_spacing + self.direction=direction + self.target=target + self.height=float(height) + self.ratio=float(ratio) + self.lens=float(lens) + self.frontClipping=float(frontClipping) + self.backClipping=float(backClipping) + self.snap_rotation=float(snap_rotation) + self.twist=float(twist) + self.mode=mode + self.circle_zoom=circle_zoom + self.fast_zoom=fast_zoom + self.ucsicon=ucsicon + self.snap_on=snap_on + self.grid_on=grid_on + self.snap_style=snap_style + self.snap_isopair=snap_isopair + def __str__(self): + output = [' 0', 'VPORT', + ' 2', self.name, + ' 70', self.flag, + _point(self.leftBottom), + _point(self.rightTop,1), + _point(self.center,2), # View center point (in DCS) + _point(self.snap_base,3), + _point(self.snap_spacing,4), + _point(self.grid_spacing,5), + _point(self.direction,6), #view direction from target (in WCS) + _point(self.target,7), + ' 40', self.height, + ' 41', self.ratio, + ' 42', self.lens, + ' 43', self.frontClipping, + ' 44', self.backClipping, + ' 50', self.snap_rotation, + ' 51', self.twist, + ' 71', self.mode, + ' 72', self.circle_zoom, + ' 73', self.fast_zoom, + ' 74', self.ucsicon, + ' 75', self.snap_on, + ' 76', self.grid_on, + ' 77', self.snap_style, + ' 78', self.snap_isopair + ] + + output_str = '' + for s in output: + output_str += '%s\n' %s + return output_str + + + +#----------------------------------------------- +class View(_Call): + def __init__(self,name,flag=0, + width=1, + height=1, + center=(0.5,0.5), + direction=(0,0,1), + target=(0,0,0), + lens=50, + frontClipping=0, + backClipping=0, + twist=0,mode=0 + ): + self.name=name + self.flag=flag + self.width=float(width) + self.height=float(height) self.center=center self.direction=direction self.target=target - self.lens=lens - self.frontClipping=frontClipping - self.backClipping=backClipping - self.twist=twist + self.lens=float(lens) + self.frontClipping=float(frontClipping) + self.backClipping=float(backClipping) + self.twist=float(twist) self.mode=mode def __str__(self): - return ' 0\nVIEW\n 2\n%s\n 70\n%s\n 40\n%s\n%s\n 41\n%s\n%s\n%s\n 42\n%s\n 43\n%s\n 44\n%s\n 50\n%s\n 71\n%s\n'%\ - (self.name,self.flag,self.height,_point(self.center),self.width, - _point(self.direction,1),_point(self.target,2),self.lens, - self.frontClipping,self.backClipping,self.twist,self.mode) + output = [' 0', 'VIEW', + ' 2', self.name, + ' 70', self.flag, + ' 40', self.height, + _point(self.center), + ' 41', self.width, + _point(self.direction,1), + _point(self.target,2), + ' 42', self.lens, + ' 43', self.frontClipping, + ' 44', self.backClipping, + ' 50', self.twist, + ' 71', self.mode + ] + output_str = '' + for s in output: + output_str += '%s\n' %s + return output_str #----------------------------------------------- def ViewByWindow(name,leftBottom=(0,0),rightTop=(1,1),**options): @@ -601,7 +724,7 @@ class Drawing(_Collection): """Dxf drawing. Use append or any other list methods to add objects.""" def __init__(self,insbase=(0.0,0.0,0.0),extmin=(0.0,0.0,0.0),extmax=(0.0,0.0,0.0), layers=[Layer()],linetypes=[LineType()],styles=[Style()],blocks=[], - views=[],entities=None,fileName='test.dxf'): + views=[],vports=[],entities=None,fileName='test.dxf'): # TODO: replace list with None,arial if not entities: entities=[] @@ -613,6 +736,7 @@ class Drawing(_Collection): self.linetypes=copy.copy(linetypes) self.styles=copy.copy(styles) self.views=copy.copy(views) + self.vports=copy.copy(vports) self.blocks=copy.copy(blocks) self.fileName=fileName #private @@ -656,7 +780,8 @@ class Drawing(_Collection): header=[self.acadver]+[self._point(attr,getattr(self,attr))+'\n' for attr in _HEADER_POINTS] header=self._section('header',header) - tables=[self._table('ltype',[str(x) for x in self.linetypes]), + tables=[self._table('vport',[str(x) for x in self.vports]), + self._table('ltype',[str(x) for x in self.linetypes]), self._table('layer',[str(x) for x in self.layers]), self._table('style',[str(x) for x in self.styles]), self._table('view',[str(x) for x in self.views]), @@ -740,17 +865,16 @@ def test(): d.append(Line(points=[(0,0,0),(1,1,1)])) d.append(Mtext('Click on Ads\nmultiple lines with mtext',point=(1,1,1),color=5,rotation=90)) d.append(Text('Please donate!',point=(3,0,1))) - d.append(Rectangle(point=(2,2,2),width=4,height=3,color=6,solid=Solid(color=2))) + #d.append(Rectangle(point=(2,2,2),width=4,height=3,color=6,solid=Solid(color=2))) d.append(Solid(points=[(4,4,0),(5,4,0),(7,8,0),(9,9,0)],color=3)) - d.append(PolyLine(points=[(1,1,1),(2,1,1),(2,2,1),(1,2,1)],closed=1,color=1)) + #d.append(PolyLine(points=[(1,1,1),(2,1,1),(2,2,1),(1,2,1)],flag=1,color=1)) #d.saveas('c:\\test.dxf') d.saveas('test.dxf') - #----------------------------------------------------- if __name__=='__main__': if not copy: Draw.PupMenu('Error%t|This script requires a full python install') - else: main() + else: test() \ No newline at end of file