[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [2292] contrib/py/scripts/addons: DXF-exporter script - initial files

Remigiusz Fiedler migius at gmx.net
Fri Sep 2 00:42:52 CEST 2011


Revision: 2292
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=2292
Author:   migius
Date:     2011-09-01 22:42:52 +0000 (Thu, 01 Sep 2011)
Log Message:
-----------
DXF-exporter script - initial files
submited by Vaclav Klecanda

Added Paths:
-----------
    contrib/py/scripts/addons/io_export_dxf/
    contrib/py/scripts/addons/io_export_dxf/__init__.py
    contrib/py/scripts/addons/io_export_dxf/draw_blenders/
    contrib/py/scripts/addons/io_export_dxf/draw_blenders/__init__.py
    contrib/py/scripts/addons/io_export_dxf/dxfLibrary.py
    contrib/py/scripts/addons/io_export_dxf/export_dxf.py
    contrib/py/scripts/addons/io_export_dxf/model.py
    contrib/py/scripts/addons/io_export_dxf/operator.py
    contrib/py/scripts/addons/io_export_dxf/primitive_exporters/
    contrib/py/scripts/addons/io_export_dxf/primitive_exporters/__init__.py
    contrib/py/scripts/addons/io_export_dxf/primitive_exporters/base_exporter.py
    contrib/py/scripts/addons/io_export_dxf/primitive_exporters/camera_exporter.py
    contrib/py/scripts/addons/io_export_dxf/primitive_exporters/curve_exporter.py
    contrib/py/scripts/addons/io_export_dxf/primitive_exporters/empty_exporter.py
    contrib/py/scripts/addons/io_export_dxf/primitive_exporters/insert_exporter.py
    contrib/py/scripts/addons/io_export_dxf/primitive_exporters/lamp_exporter.py
    contrib/py/scripts/addons/io_export_dxf/primitive_exporters/mesh_exporter.py
    contrib/py/scripts/addons/io_export_dxf/primitive_exporters/text_exporter.py
    contrib/py/scripts/addons/io_export_dxf/primitive_exporters/viewborder_exporter.py

Added: contrib/py/scripts/addons/io_export_dxf/__init__.py
===================================================================
--- contrib/py/scripts/addons/io_export_dxf/__init__.py	                        (rev 0)
+++ contrib/py/scripts/addons/io_export_dxf/__init__.py	2011-09-01 22:42:52 UTC (rev 2292)
@@ -0,0 +1,47 @@
+#  ***** GPL LICENSE BLOCK *****
+#
+#  This program is free software: you can redistribute it and/or modify
+#  it under the terms of the GNU General Public License as published by
+#  the Free Software Foundation, either version 3 of the License, or
+#  (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#  All rights reserved.
+#  ***** GPL LICENSE BLOCK *****
+
+bl_info = {
+    "name": "Export Autocad DXF Format (.dxf)",
+    "author": "Remigiusz Fiedler (AKA migius)",
+    "version": (2, 1, 2),
+    "blender": (2, 5, 8),
+    "api": 37702,
+    "location": "File > Export > Autodesk (.dxf)",
+    "description": "The script exports Blender geometry to DXF format r12 version.",
+    "warning": "",
+    "wiki_url": "http://wiki.blender.org/index.php/Scripts/Manual/Export/autodesk_dxf",
+    "tracker_url": "https://projects.blender.org/tracker/index.php?func=detail&aid=22795",
+    "category": "Import-Export"
+}
+
+import bpy
+from .operator import DXFExporter
+
+def menu_func(self, context):
+    self.layout.operator(DXFExporter.bl_idname, text="Autocad (.dxf)")
+
+def register():
+    bpy.utils.register_module(__name__)
+    bpy.types.INFO_MT_file_export.append(menu_func)
+
+def unregister():
+    bpy.utils.unregister_module(__name__)
+    bpy.types.INFO_MT_file_export.remove(menu_func)
+
+if __name__ == "__main__":
+    register()
\ No newline at end of file

Added: contrib/py/scripts/addons/io_export_dxf/draw_blenders/__init__.py
===================================================================
--- contrib/py/scripts/addons/io_export_dxf/draw_blenders/__init__.py	                        (rev 0)
+++ contrib/py/scripts/addons/io_export_dxf/draw_blenders/__init__.py	2011-09-01 22:42:52 UTC (rev 2292)
@@ -0,0 +1,86 @@
+""" NOTE:
+This stuff was in original code but it is no longer needed.
+"""
+
+#-----------------------------------------------------
+def mesh_drawBlender(vertList, edgeList, faceList, name="dxfMesh", flatten=False, AT_CUR=True, link=True):
+    #print 'deb:mesh_drawBlender started XXXXXXXXXXXXXXXXXX' #---------
+    ob = Object.New("Mesh",name)
+    me = Mesh.New(name)
+    #print 'deb: vertList=\n', vertList #---------
+    #print 'deb: edgeList=\n', edgeList #---------
+    #print 'deb: faceList=\n', faceList #---------
+    me.verts.extend(vertList)
+    if edgeList: me.edges.extend(edgeList)
+    if faceList: me.faces.extend(faceList)
+    if flatten:
+        for v in me.verts: v.co.z = 0.0
+    ob.link(me)
+    if link:
+        sce = Scene.getCurrent()
+        sce.objects.link(ob)
+        #me.triangleToQuad()
+        if AT_CUR:
+            cur_loc = Window.GetCursorPos()
+            ob.setLocation(cur_loc)
+        Blender.Redraw()
+    #return ob
+
+#-----------------------------------------------------
+def curve_drawBlender(vertList, org_point=[0.0,0.0,0.0], closed=0, name="dxfCurve", flatten=False, AT_CUR=True, link=True):
+    #print 'deb:curve_drawBlender started XXXXXXXXXXXXXXXXXX' #---------
+    ob = Object.New("Curve",name)
+    cu = Curve.New(name)
+    #print 'deb: vertList=\n', vertList #---------
+    curve = cu.appendNurb(BezTriple.New(vertList[0][0]))
+    for p in vertList[1:]:
+        curve.append(BezTriple.New(p[0]))
+    for point in curve:
+        #point.handleTypes = [VECT, VECT]
+        point.handleTypes = [FREE, FREE]
+        point.radius = 1.0
+    curve.flagU = closed # 0 sets the curve not cyclic=open
+    cu.setResolu(6)
+    cu.update() #important for handles calculation
+    if flatten:
+        for v in cu.verts: v.co.z = 0.0
+    ob.link(cu)
+    if link:
+        sce = Scene.getCurrent()
+        sce.objects.link(ob)
+        #me.triangleToQuad()
+        if AT_CUR:
+            cur_loc = Window.GetCursorPos()
+            ob.setLocation(cur_loc)
+        elif org_point:
+            cur_loc=org_point
+            ob.setLocation(cur_loc)
+        Blender.Redraw()
+    #return ob
+    
+#-----------------------------------------------------
+def drawClipBox(clip_box):
+    """debug tool: draws Clipping-Box of a Camera View
+    """
+    min_X1, max_X1, min_Y1, max_Y1,\
+    min_X2, max_X2, min_Y2, max_Y2,\
+        min_Z, max_Z = clip_box
+    verts = []
+    verts.append([min_X1, min_Y1, min_Z])
+    verts.append([max_X1, min_Y1, min_Z])
+    verts.append([max_X1, max_Y1, min_Z])
+    verts.append([min_X1, max_Y1, min_Z])
+    verts.append([min_X2, min_Y2, max_Z])
+    verts.append([max_X2, min_Y2, max_Z])
+    verts.append([max_X2, max_Y2, max_Z])
+    verts.append([min_X2, max_Y2, max_Z])
+    faces = [[0,1,2,3],[4,5,6,7]]
+    newmesh = Mesh.New()
+    newmesh.verts.extend(verts)
+    newmesh.faces.extend(faces)
+    
+    plan = Object.New('Mesh','clip_box')
+    plan.link(newmesh)
+    sce = Scene.GetCurrent()
+    sce.objects.link(plan)
+    plan.setMatrix(sce.objects.camera.matrix)

Added: contrib/py/scripts/addons/io_export_dxf/dxfLibrary.py
===================================================================
--- contrib/py/scripts/addons/io_export_dxf/dxfLibrary.py	                        (rev 0)
+++ contrib/py/scripts/addons/io_export_dxf/dxfLibrary.py	2011-09-01 22:42:52 UTC (rev 2292)
@@ -0,0 +1,927 @@
+#dxfLibrary.py : provides functions for generating DXF files
+# --------------------------------------------------------------------------
+__version__ = "v1.35 - 2010.06.23"
+__author__ = "Stani Michiels(Stani), Remigiusz Fiedler(migius)"
+__license__ = "GPL"
+__url__ = "http://wiki.blender.org/index.php/Extensions:2.4/Py/Scripts/Export/DXF"
+__bpydoc__ ="""The library to export geometry data to DXF format r12 version.
+
+Copyright %s
+Version %s
+License %s
+Homepage %s
+
+See the homepage for documentation.
+Dedicated thread on BlenderArtists: http://blenderartists.org/forum/showthread.php?t=136439
+
+IDEAs:
+-
+
+TODO:
+- add support for DXFr14 version (needs extended file header)
+- add support for DXF-SPLINEs (possible first in DXFr14 version)
+- add support for DXF-MTEXT
+- add user preset for floating point precision (3-16?)
+
+History
+v1.35 - 2010.06.23 by migius
+ - added (as default) writing to DXF file without RAM-buffering: faster and low-RAM-machines friendly
+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
+ - 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
+v1.31 - 2009.06.02 by migius
+ - modif _Entity class: added paperspace,elevation
+v1.30 - 2009.05.28 by migius
+ - bugfix 3dPOLYLINE/POLYFACE: VERTEX needs x,y,z coordinates, index starts with 1 not 0
+v1.29 - 2008.12.28 by Yorik
+ - modif POLYLINE to support bulge segments
+v1.28 - 2008.12.13 by Steeve/BlenderArtists
+ - bugfix for EXTMIN/EXTMAX to suit Cycas-CAD
+v1.27 - 2008.10.07 by migius
+ - beautifying output code: keys whitespace prefix
+ - refactoring DXF-strings format: NewLine moved to the end of
+v1.26 - 2008.10.05 by migius
+ - modif POLYLINE to support POLYFACE
+v1.25 - 2008.09.28 by migius
+ - modif FACE class for r12
+v1.24 - 2008.09.27 by migius
+ - modif POLYLINE class for r12
+ - changing output format from r9 to r12(AC1009)
+v1.1 (20/6/2005) by www.stani.be/python/sdxf
+ - Python library to generate dxf drawings
+______________________________________________________________
+""" % (__author__,__version__,__license__,__url__)
+
+# --------------------------------------------------------------------------
+# DXF Library: copyright (C) 2005 by Stani Michiels (AKA Stani)
+#                       2008/2009 modif by Remigiusz Fiedler (AKA migius)
+# --------------------------------------------------------------------------
+# ***** BEGIN GPL LICENSE BLOCK *****
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+#
+# ***** END GPL LICENCE BLOCK *****
+
+
+#import Blender
+#from Blender import Mathutils, Window, Scene, sys, Draw
+#import BPyMessages
+
+try:
+	import copy
+	#from struct import pack
+except:
+	copy = None
+
+####1) Private (only for developpers)
+_HEADER_POINTS=['insbase','extmin','extmax']
+
+#---helper functions-----------------------------------
+def _point(x,index=0):
+	"""Convert tuple to a dxf point"""
+	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"""
+	out = '\n'.join([_point(plist[i],i)for i in range(len(plist))])
+	return out
+
+#---base classes----------------------------------------
+class _Call:
+	"""Makes a callable class."""
+	def copy(self):
+		"""Returns a copy."""
+		return copy.deepcopy(self)
+
+	def __call__(self,**attrs):
+		"""Returns a copy with modified attributes."""
+		copied=self.copy()
+		for attr in attrs:setattr(copied,attr,attrs[attr])
+		return copied
+
+#-------------------------------------------------------
+class _Entity(_Call):

@@ Diff output truncated at 10240 characters. @@


More information about the Bf-extensions-cvs mailing list