[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [1336] trunk/py/scripts/addons/ io_import_scene_dxf.py: moved to trunk
Remigiusz Fiedler
migius at gmx.net
Mon Jan 3 02:35:16 CET 2011
Revision: 1336
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-extensions&revision=1336
Author: migius
Date: 2011-01-03 02:35:16 +0100 (Mon, 03 Jan 2011)
Log Message:
-----------
moved to trunk
Added Paths:
-----------
trunk/py/scripts/addons/io_import_scene_dxf.py
Copied: trunk/py/scripts/addons/io_import_scene_dxf.py (from rev 1335, contrib/py/scripts/addons/io_import_scene_dxf.py)
===================================================================
--- trunk/py/scripts/addons/io_import_scene_dxf.py (rev 0)
+++ trunk/py/scripts/addons/io_import_scene_dxf.py 2011-01-03 01:35:16 UTC (rev 1336)
@@ -0,0 +1,2506 @@
+# ##### 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# ##### END GPL LICENSE BLOCK #####
+
+"""
+Release note by migius (DXF support maintainer) 2011.01.02:
+Script supports only a small part of DXF specification:
+- imports LINE, ARC, CIRCLE, ELLIPSE, SOLID, TRACE, POLYLINE, LWPOLYLINE
+- imports TEXT, MTEXT
+- supports 3d-rotation of entities (210 group)
+- supports THICKNESS for SOLID, TRACE, LINE, ARC, CIRCLE, ELLIPSE
+- ignores WIDTH, THICKNESS, BULGE in POLYLINE/LWPOLYLINE
+- ignores face-data in POLYFACE / POLYMESH
+- ignores TEXT 2d-rotation
+- ignores hierarchies (BLOCK, INSERT, GROUP)
+- ignores LAYER
+- ignores COLOR, LINEWIDTH, LINESTYLE
+
+This script is a temporary solution.
+Probably no more improvements will be done to this script.
+The full-feature importer script from 2.49 will be back in 2.6 release.
+
+Installation:
+Place this file to Blender addons directory (on Windows it is %Blender_directory%\2.53\scripts\addons\)
+You must activate the script in the "Add-Ons" tab (user preferences).
+Access it from File > Import menu.
+
+History:
+ver 0.1.3 - 2011.01.02 by migius
+- added draw curves as sequence for "Draw_as_Curve"
+- added toggle "Draw as one" as user preset in UI
+- added draw POINT as mesh-vertex
+- added draw_THICKNESS for LINE, ARC, CIRCLE, ELLIPSE, LWPOLYLINE and POLYLINE
+- added draw_THICKNESS for SOLID, TRACE
+ver 0.1.2 - 2010.12.27 by migius
+- added draw() for TRACE
+- fixed wrong vertex order in SOLID
+- added CIRCLE resolution as user preset in UI
+- added closing segment for circular LWPOLYLINE and POLYLINE
+- fixed registering for 2.55beta
+ver 0.1.1 - 2010.09.07 by migius
+- fixed dxf-file names recognition limited to ".dxf"
+- fixed registering for 2.53beta
+ver 0.1 - 2010.06.10 by Thomas Larsson
+"""
+
+bl_addon_info = {
+ 'name': 'Import Autocad DXF (.dxf)',
+ 'author': 'Thomas Larsson',
+ 'version': (0,1,3),
+ 'blender': (2, 5, 6),
+ 'api': 32738,
+ 'location': 'File > Import',
+ 'description': 'Import files in the Autocad DXF format (.dxf)',
+ 'warning': 'supporting only a sub-set of DXF specification',
+ 'wiki_url': 'http://wiki.blender.org/index.php/Extensions:2.5/Py/Scripts/Import-Export/DXF_Importer',
+ 'tracker_url': 'https://projects.blender.org/tracker/index.php?func=detail&aid=23480&group_id=153&atid=468',
+ 'category': 'Import-Export'}
+
+__version__ = '.'.join([str(s) for s in bl_addon_info['version']])
+
+import os
+import codecs
+import math
+from math import sin, cos, radians
+import bpy
+import mathutils
+from mathutils import Vector, Matrix
+
+#
+# Global flags
+#
+
+T_Merge = 0x01
+T_NewScene = 0x02
+T_Curves = 0x04
+T_DrawOne = 0x08
+T_Debug = 0x10
+T_Verbose = 0x20
+T_ThicON = 0x40
+
+toggle = T_Merge | T_NewScene | T_DrawOne | T_ThicON
+theCircleRes = 32
+theMergeLimit = 1e-5
+
+#
+# class CSection:
+#
+
+class CSection:
+ type = None
+
+ def __init__(self):
+ self.data = []
+
+ def display(self):
+ print("Section", self.type)
+ for datum in self.data:
+ datum.display()
+
+#
+# class CTable:
+#
+
+class CTable:
+ def __init__(self):
+ self.type = None
+ self.name = None
+ self.handle = None
+ self.owner = None
+ self.subclass = None
+ self.nEntries = 0
+ def display(self):
+ print("Table %s %s %s %s %s %d" % (self.type, self.name, self.handle, self.owner, self.subclass, self.nEntries))
+
+#
+# class CEntity:
+#
+class CEntity:
+ def __init__(self, typ, drawtype):
+ self.type = typ
+ self.drawtype = drawtype
+ self.handle = None
+ self.owner = None
+ self.subclass = None
+ self.layer = 0
+ self.color = 0
+ self.invisible = 0
+ self.linetype_name = ''
+ self.linetype_scale = 1.0
+ self.paperspace = 0
+ #self.normal = Vector((0,0,1))
+
+ def display(self):
+ print("Entity %s %s %s %s %s %s %x" %
+ (self.type, self.handle, self.owner, self.subclass, self.layer, self.color, self.invisible))
+
+ def build(self, vn=0):
+ global toggle
+ if toggle & T_Debug:
+ raise NameError("Warning: can not build - unsupported entity type: %s" % self.type)
+ return(([], [], [], vn))
+
+ def draw(self):
+ global toggle
+ if toggle & T_Debug:
+ raise NameError("Warning: can not draw - unsupported entity type: %s" % self.type)
+ return
+
+
+DxfCommonAttributes = {
+ 5 : 'handle',
+ 6 : 'linetype_name',
+ 8 : 'layer',
+ 48 : 'linetype_scale',
+ 60 : 'invisible',
+ 62 : 'color',
+ 67 : 'paperspace',
+ 100 : 'subclass',
+ 330 : 'owner',
+ 360 : 'owner',
+}
+
+#
+# class C3dFace(CEntity):
+# 10 : 'point0.x', 20 : 'point0.y', 30 : 'point0.z',
+# 11 : 'point1.x', 21 : 'point1.y', 31 : 'point1.z',
+# 12 : 'point2.x', 22 : 'point2.y', 32 : 'point2.z',
+# 13 : 'point3.x', 23 : 'point3.y', 33 : 'point3.z',
+# 70 : 'flags',
+#
+
+class C3dFace(CEntity):
+ def __init__(self):
+ CEntity.__init__(self, '3DFACE', 'Mesh')
+ self.point0 = Vector()
+ self.point1 = Vector()
+ self.point2 = Vector()
+ self.point3 = Vector()
+
+ def display(self):
+ CEntity.display(self)
+ print(self.point0)
+ print(self.point1)
+ print(self.point2)
+ print(self.point3)
+
+ def build(self, vn=0):
+ verts = [self.point0, self.point1, self.point2]
+ if self.point3 == Vector((0,0,0)) or self.point2 == self.point3:
+ faces = [(vn+0, vn+1, vn+2)]
+ vn += 3
+ else:
+ verts.append( self.point3 )
+ faces = [(vn+0, vn+1, vn+2, vn+3)]
+ vn += 4
+ return((verts, [], faces, vn))
+
+#
+# class C3dSolid(CEntity):
+# 1 : 'data', 3 : 'more', 70 : 'version',
+#
+
+class C3dSolid(CEntity):
+ def __init__(self):
+ CEntity.__init__(self, '3DSOLID', 'Mesh')
+ self.data = None
+ self.more = None
+ self.version = 0
+
+#
+# class CAcadProxyEntity(CEntity):
+# 70 : 'format',
+# 90 : 'id', 91 : 'class', 92 : 'graphics_size', 93 : 'entity_size', 95: 'format',
+# 310 : 'data', 330 : 'id1', 340 : 'id2', 350 : 'id3', 360 : 'id4',
+#
+
+class CAcadProxyEntity(CEntity):
+ def __init__(self):
+ CEntity.__init__(self, 'ACAD_PROXY_ENTITY', None)
+
+
+#
+# class CArc(CEntity):
+# 10 : 'center.x', 20 : 'center.y', 30 : 'center.z',
+# 40 : 'radius',
+# 50 : 'start_angle', 51 : 'end_angle'
+#
+
+class CArc(CEntity):
+ def __init__(self):
+ CEntity.__init__(self, 'ARC', 'Mesh')
+ self.center = Vector()
+ self.radius = 0.0
+ self.start_angle = 0.0
+ self.end_angle = 0.0
+ self.thickness = 0.0
+ self.normal = Vector((0,0,1))
+
+ def display(self):
+ CEntity.display(self)
+ print(self.center)
+ print("%.4f %.4f %.4f " % (self.radius, self.start_angle, self.end_angle))
+
+ def build(self, vn=0):
+ start, end = self.start_angle, self.end_angle
+ if end > 360: end = end % 360.0
+ if end < start: end +=360.0
+ angle = end - start
+
+ deg2rad = math.pi/180.0
+ start *= deg2rad
+ end *= deg2rad
+ dphi = end - start
+ phi0 = start
+ w = dphi/theCircleRes
+ r = self.radius
+ center = self.center
+ v0 = vn
+ points = []
+ edges, faces = [], []
+ for n in range(theCircleRes):
+ s = math.sin(n*w + phi0)
+ c = math.cos(n*w + phi0)
+ v = center + Vector((r*c, r*s, 0.0))
+ points.append(v)
+ pn = len(points)
+ thic = self.thickness
+ t_vector = Vector((0, 0, thic))
+ if thic != 0 and (toggle & T_ThicON):
+ thic_points = [v + t_vector for v in points]
+ if thic < 0.0:
+ thic_points.extend(points)
+ points = thic_points
+ else:
+ points.extend(thic_points)
+ faces = [(v0+nr+0,v0+nr+1,v0+pn+nr+1,v0+pn+nr+0) for nr in range(pn)]
+ faces.pop()
+ self.drawtype = 'Mesh'
+ vn += 2*pn
+ else:
+ edges = [(v0+nr+0,v0+nr+1) for nr in range(pn)]
+ edges.pop()
+ vn += pn
+
+ if self.normal!=Vector((0,0,1)):
+ ma = getOCS(self.normal)
+ if ma:
+ #ma.invert()
+ points = [v * ma for v in points]
+ #print ('arc vn=', vn)
+ #print ('faces=', len(faces))
+ return ((points, edges, faces, vn))
+
+#
+# class CArcAlignedText(CEntity):
+# 1 : 'text', 2 : 'font', 3 : 'bigfont', 7 : 'style',
+# 10 : 'center.x', 20 : 'center.y', 30 : 'center.z',
+# 40 : 'radius', 41 : 'width', 42 : 'height', 43 : 'spacing',
+# 44 : 'offset', 45 : 'right_offset', 46 : 'left_offset',
+# 50 : 'start_angle', 51 : 'end_angle',
+# 70 : 'order', 71 : 'direction', 72 : 'alignment', 73 : 'side',
+# 74 : 'bold', 75 : 'italic', 76 : 'underline',
+# 77 : 'character_set', 78 : 'pitch', 79 'fonttype',
+# 90 : 'color',
+# 280 : 'wizard', 330 : 'id'
+#
+
+class CArcAlignedText(CEntity):
+ def __init__(self):
+ CEntity.__init__(self, 'ARCALIGNEDTEXT', 'Mesh')
+ self.text = ""
+ self.style = ""
+ self.center = Vector()
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list