[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [1335] contrib/py/scripts/addons/ io_import_scene_dxf.py: DXF-importer update

Remigiusz Fiedler migius at gmx.net
Mon Jan 3 01:58:10 CET 2011


Revision: 1335
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-extensions&revision=1335
Author:   migius
Date:     2011-01-03 01:58:10 +0100 (Mon, 03 Jan 2011)

Log Message:
-----------
DXF-importer update
v.0.1.3 - 2011.01.02 by migius
- updated for 2.56
- complex refactoring, many improvements, changes, bugfixes

Modified Paths:
--------------
    contrib/py/scripts/addons/io_import_scene_dxf.py

Modified: contrib/py/scripts/addons/io_import_scene_dxf.py
===================================================================
--- contrib/py/scripts/addons/io_import_scene_dxf.py	2011-01-02 02:12:07 UTC (rev 1334)
+++ contrib/py/scripts/addons/io_import_scene_dxf.py	2011-01-03 00:58:10 UTC (rev 1335)
@@ -16,62 +16,85 @@
 #
 # ##### END GPL LICENSE BLOCK #####
 
-bl_addon_info = {
-    'name': 'Import Autocad DXF (.dxf)',
-    'author': 'Thomas Larsson',
-    'version': (0, 1),
-    'blender': (2, 5, 3),
-    'api': 31667,
-    'location': 'File > Import',
-    'description': 'Import files in the Autocad DXF format (.dxf)',
-    'warning': '', # used for warning icon and text in addons panel
-    'wiki_url': 'http://wiki.blender.org/index.php/Extensions:2.5/Py/'\
-        'Scripts/Import-Export/Import_DXF_(.dxf)',
-    'tracker_url': 'https://projects.blender.org/tracker/index.php?'\
-        'func=detail&aid=23480&group_id=153&atid=468',
-    'category': 'Import-Export'}
-
 """
-Release note by migius (DXF support maintainer) 2010.06.14:
-- script works well for simple 2d objects
-- limited support for complex entities like POLYLINE / POLYFACE / POLYMESH
-- erroneous rotated TEXTs
-- no support for entity rotation in 3d (210 group ignored)
-- no support for hierarchies (BLOCKs)
-Most probably no additions will be made to this script.
-It is a temporary solution - the old full feature importer will be ported to 2.6 soon.
+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 have to activated the script in the "Add-Ons" tab (user preferences).
-Access from the File > Import menu.
+You must activate the script in the "Add-Ons" tab (user preferences).
+Access it from File > Import menu.
 
 History:
-ver 0.11 - 2010.09.07 by migius
+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
+from mathutils import Vector, Matrix
 
 #
 #    Global flags
 #
 
 T_Merge = 0x01
-T_Replace = 0x02
+T_NewScene = 0x02
 T_Curves = 0x04
-T_Verbose = 0x08
+T_DrawOne = 0x08
 T_Debug = 0x10
+T_Verbose = 0x20
+T_ThicON = 0x40
 
-toggle = T_Merge | T_Replace 
-
+toggle = T_Merge | T_NewScene | T_DrawOne | T_ThicON
+theCircleRes = 32
 theMergeLimit = 1e-5
 
 #
@@ -120,22 +143,22 @@
         self.linetype_name = ''
         self.linetype_scale = 1.0
         self.paperspace = 0
-        self.extrusion = Vector()
+        #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):
+    def build(self, vn=0):
         global toggle
         if toggle & T_Debug:
-            raise NameError("Cannot build %s yet" % self.type)
-        return(([], [], vn)) 
+            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("Cannot draw %s yet" % self.type)
+            raise NameError("Warning: can not draw - unsupported entity type: %s" % self.type)
         return
 
 
@@ -150,7 +173,6 @@
     100 : 'subclass',
     330 : 'owner',
     360 : 'owner',
-    210 : 'extrusion.x', 220 : 'extrusion.y', 230 : 'extrusion.z', 
 }
 
 #
@@ -164,7 +186,7 @@
 
 class C3dFace(CEntity):
     def __init__(self):
-        CEntity.__init__(self, '3DFACE', 'Face')
+        CEntity.__init__(self, '3DFACE', 'Mesh')
         self.point0 = Vector()
         self.point1 = Vector()
         self.point2 = Vector()
@@ -177,16 +199,16 @@
         print(self.point2)
         print(self.point3)
 
-    def build(self, vn):
+    def build(self, vn=0):
         verts = [self.point0, self.point1, self.point2]
-        if self.point2 == self.point3:
-            face = (vn, vn+1, vn+2)
+        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 )
-            face = (vn, vn+1, vn+2, vn+3)
+            faces = [(vn+0, vn+1, vn+2, vn+3)]
             vn += 4            
-        return((verts, [face], vn))
+        return((verts, [], faces, vn))
 
 #
 #    class C3dSolid(CEntity):
@@ -195,7 +217,7 @@
 
 class C3dSolid(CEntity):
     def __init__(self):
-        CEntity.__init__(self, '3DSOLID', 'Face')
+        CEntity.__init__(self, '3DSOLID', 'Mesh')
         self.data = None
         self.more = None
         self.version = 0
@@ -221,35 +243,69 @@
 
 class CArc(CEntity):
     def __init__(self):
-        CEntity.__init__(self, 'ARC', 'Edge')
+        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):
-        dphi = (self.end_angle - self.start_angle)*math.pi/180
-        phi0 = self.start_angle*math.pi/180
-        w = dphi/32
+    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
-        verts = []
-        edges = []
-        for n in range(32):
+        v0 = vn
+        points = []
+        edges, faces = [], []
+        for n in range(theCircleRes):
             s = math.sin(n*w + phi0)
             c = math.cos(n*w + phi0)
-            v = (center.x + r*c, center.y + r*s, center.z)
-            verts.append(v)
-            edges.append((vn,vn+1))
-            vn += 1
-        edges.pop()
-        return( (verts, edges, vn) )
+            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',
@@ -266,7 +322,7 @@
 
 class CArcAlignedText(CEntity):
     def __init__(self):
-        CEntity.__init__(self, 'ARCALIGNEDTEXT', 'Edge')
+        CEntity.__init__(self, 'ARCALIGNEDTEXT', 'Mesh')
         self.text = ""
         self.style = ""
         self.center = Vector()
@@ -292,6 +348,7 @@
         self.color = 0
         self.wizard = None
         self.id = None
+        self.normal = Vector((0,0,1))
 
 
 #
@@ -322,9 +379,10 @@
         self.text_generation_flags = 0
         self.horizontal_justification = 0.0
         self.vertical_justification = 0.0
+        self.normal = Vector((0,0,1))
 
     def draw(self):
-        drawText(self.text,  self.insertion_point, self.height, self.x_scale, self.rotation_angle, self.oblique_angle)
+        drawText(self.text,  self.insertion_point, self.height, self.x_scale, self.rotation_angle, self.oblique_angle, self.normal)
         return
 
 #
@@ -357,9 +415,10 @@
         self.text_generation_flags = 0
         self.horizontal_justification = 0.0
         self.vertical_justification = 0.0

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list