DXF exporter, dxf-library.py updated

v1.28 - 2008.12.13 by Steeve/BlenderArtists
- bugfix for EXTMIN/EXTMAX to suit Cycas-CAD
This commit is contained in:
2008-12-14 21:26:24 +00:00
parent c794e13ba3
commit e7c0666d96

View File

@@ -1,10 +1,10 @@
#dxfLibrary.py : provides functions for generating DXF files #dxfLibrary.py : provides functions for generating DXF files
# -------------------------------------------------------------------------- # --------------------------------------------------------------------------
__version__ = "v1.27beta - 2008.10.05" __version__ = "v1.28beta - 2008.12.13"
__author__ = "Stani Michiels(Stani), Remigiusz Fiedler(migius)" __author__ = "Stani Michiels(Stani), Remigiusz Fiedler(migius)"
__license__ = "GPL" __license__ = "GPL"
__url__ = "http://wiki.blender.org/index.php/Scripts/Manual/Export/autodesk_dxf" __url__ = "http://wiki.blender.org/index.php/Scripts/Manual/Export/autodesk_dxf"
__bpydoc__ ="""The script exports geometry data to DXF format r12 version. __bpydoc__ ="""The library to export geometry data to DXF format r12 version.
Copyright %s Copyright %s
Version %s Version %s
@@ -12,15 +12,17 @@ License %s
Homepage %s Homepage %s
See the homepage for documentation. See the homepage for documentation.
url: Dedicated thread on BlenderArtists: http://blenderartists.org/forum/showthread.php?t=136439
IDEAs: IDEAs:
- -
TODO: TODO:
- - add support for SPLINEs
History History
v1.28 - 2008.12.13 by Steeve/BlenderArtists
- bugfix for EXTMIN/EXTMAX to suit Cycas-CAD
v1.27 - 2008.10.07 by migius v1.27 - 2008.10.07 by migius
- beautifying output code: keys whitespace prefix - beautifying output code: keys whitespace prefix
- refactoring DXF-strings format: NewLine moved to the end of - refactoring DXF-strings format: NewLine moved to the end of
@@ -154,56 +156,56 @@ BYBLOCK=0
BYLAYER=256 BYLAYER=256
#---block-type flags (bit coded values, may be combined): #---block-type flags (bit coded values, may be combined):
ANONYMOUS =1 # This is an anonymous block generated by hatching, associative dimensioning, other internal operations, or an application ANONYMOUS =1 # This is an anonymous block generated by hatching, associative dimensioning, other internal operations, or an application
NON_CONSTANT_ATTRIBUTES =2 # This block has non-constant attribute definitions (this bit is not set if the block has any attribute definitions that are constant, or has no attribute definitions at all) NON_CONSTANT_ATTRIBUTES =2 # This block has non-constant attribute definitions (this bit is not set if the block has any attribute definitions that are constant, or has no attribute definitions at all)
XREF =4 # This block is an external reference (xref) XREF =4 # This block is an external reference (xref)
XREF_OVERLAY =8 # This block is an xref overlay XREF_OVERLAY =8 # This block is an xref overlay
EXTERNAL =16 # This block is externally dependent EXTERNAL =16 # This block is externally dependent
RESOLVED =32 # This is a resolved external reference, or dependent of an external reference (ignored on input) RESOLVED =32 # This is a resolved external reference, or dependent of an external reference (ignored on input)
REFERENCED =64 # This definition is a referenced external reference (ignored on input) REFERENCED =64 # This definition is a referenced external reference (ignored on input)
#---mtext flags #---mtext flags
#attachment point #attachment point
TOP_LEFT = 1 TOP_LEFT = 1
TOP_CENTER = 2 TOP_CENTER = 2
TOP_RIGHT = 3 TOP_RIGHT = 3
MIDDLE_LEFT = 4 MIDDLE_LEFT = 4
MIDDLE_CENTER = 5 MIDDLE_CENTER = 5
MIDDLE_RIGHT = 6 MIDDLE_RIGHT = 6
BOTTOM_LEFT = 7 BOTTOM_LEFT = 7
BOTTOM_CENTER = 8 BOTTOM_CENTER = 8
BOTTOM_RIGHT = 9 BOTTOM_RIGHT = 9
#drawing direction #drawing direction
LEFT_RIGHT = 1 LEFT_RIGHT = 1
TOP_BOTTOM = 3 TOP_BOTTOM = 3
BY_STYLE = 5 #the flow direction is inherited from the associated text style BY_STYLE = 5 #the flow direction is inherited from the associated text style
#line spacing style (optional): #line spacing style (optional):
AT_LEAST = 1 #taller characters will override AT_LEAST = 1 #taller characters will override
EXACT = 2 #taller characters will not override EXACT = 2 #taller characters will not override
#---polyline flags #---polyline flags
CLOSED =1 # This is a closed polyline (or a polygon mesh closed in the M direction) 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 CURVE_FIT =2 # Curve-fit vertices have been added
SPLINE_FIT =4 # Spline-fit vertices have been added SPLINE_FIT =4 # Spline-fit vertices have been added
POLYLINE_3D =8 # This is a 3D polyline POLYLINE_3D =8 # This is a 3D polyline
POLYGON_MESH =16 # This is a 3D polygon mesh POLYGON_MESH =16 # This is a 3D polygon mesh
CLOSED_N =32 # The polygon mesh is closed in the N direction CLOSED_N =32 # The polygon mesh is closed in the N direction
POLYFACE_MESH =64 # The polyline is a polyface mesh 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 CONTINOUS_LINETYPE_PATTERN =128 # The linetype pattern is generated continuously around the vertices of this polyline
#---text flags #---text flags
#horizontal #horizontal
LEFT = 0 LEFT = 0
CENTER = 1 CENTER = 1
RIGHT = 2 RIGHT = 2
ALIGNED = 3 #if vertical alignment = 0 ALIGNED = 3 #if vertical alignment = 0
MIDDLE = 4 #if vertical alignment = 0 MIDDLE = 4 #if vertical alignment = 0
FIT = 5 #if vertical alignment = 0 FIT = 5 #if vertical alignment = 0
#vertical #vertical
BASELINE = 0 BASELINE = 0
BOTTOM = 1 BOTTOM = 1
MIDDLE = 2 MIDDLE = 2
TOP = 3 TOP = 3
####3) Classes ####3) Classes
#---entitities ----------------------------------------------- #---entitities -----------------------------------------------
@@ -239,7 +241,7 @@ class Face(_Entity):
"""3dface""" """3dface"""
def __init__(self,points,**common): def __init__(self,points,**common):
_Entity.__init__(self,**common) _Entity.__init__(self,**common)
if len(points)<4: #fix for r12 format while len(points)<4: #fix for r12 format
points.append(points[-1]) points.append(points[-1])
self.points=points self.points=points
@@ -336,10 +338,14 @@ class PolyLine(_Entity):
#----------------------------------------------- #-----------------------------------------------
class Point(_Entity): class Point(_Entity):
"""Colored solid fill.""" """Point."""
def __init__(self,points=None,**common): def __init__(self,points=None,**common):
_Entity.__init__(self,**common) _Entity.__init__(self,**common)
self.points=points self.points=points
def __str__(self): #TODO:
return ' 0\nPOINT\n%s%s\n' %(self._common(),
_points(self.points)
)
#----------------------------------------------- #-----------------------------------------------
class Solid(_Entity): class Solid(_Entity):
@@ -468,7 +474,7 @@ class Block(_Collection):
self.name=name self.name=name
self.flag=0 self.flag=0
self.base=base self.base=base
def __str__(self): def __str__(self): #TODO:
e=''.join([str(x)for x in self.entities]) 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'%\ 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) (self.layer,self.name.upper(),self.flag,_point(self.base),self.name.upper(),e)
@@ -552,11 +558,12 @@ def ViewByWindow(name,leftBottom=(0,0),rightTop=(1,1),**options):
#----------------------------------------------- #-----------------------------------------------
class Drawing(_Collection): class Drawing(_Collection):
"""Dxf drawing. Use append or any other list methods to add objects.""" """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),extmax=(0.0,0.0), 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=[], layers=[Layer()],linetypes=[LineType()],styles=[Style()],blocks=[],
views=[],entities=None,fileName='test.dxf'): views=[],entities=None,fileName='test.dxf'):
# TODO: replace list with None,arial # TODO: replace list with None,arial
if not entities:entities=[] if not entities:
entities=[]
_Collection.__init__(self,entities) _Collection.__init__(self,entities)
self.insbase=insbase self.insbase=insbase
self.extmin=extmin self.extmin=extmin
@@ -680,9 +687,9 @@ def test():
#Drawing #Drawing
d=Drawing() d=Drawing()
#tables #tables
d.blocks.append(b) #table blocks d.blocks.append(b) #table blocks
d.styles.append(Style()) #table styles d.styles.append(Style()) #table styles
d.views.append(View('Normal')) #table view d.views.append(View('Normal')) #table view
d.views.append(ViewByWindow('Window',leftBottom=(1,0),rightTop=(2,1))) #idem d.views.append(ViewByWindow('Window',leftBottom=(1,0),rightTop=(2,1))) #idem
#entities #entities