[Bf-extensions-cvs] [68e4b7e] master: Proper error message for DXF versions below AC1009. Users get notified that DXF files with version below AC1009 (DXF12) are not supported. This is because there is not enough documentation available for those versions. Users with files that old are kindly requested to export their projects to newer versions. In some cases it might also work to just replace AC1006 (or anything below AC1009) with AC1009 directly in the DXF.

Lukas Treyer noreply at git.blender.org
Tue Oct 21 16:39:23 CEST 2014


Commit: 68e4b7e6bf9ddd643bd8ac9b48b8b9aeaeae4b03
Author: Lukas Treyer
Date:   Tue Oct 21 16:37:45 2014 +0200
Branches: master
https://developer.blender.org/rBA68e4b7e6bf9ddd643bd8ac9b48b8b9aeaeae4b03

Proper error message for DXF versions below AC1009. Users get notified that DXF files with version below AC1009 (DXF12) are not supported. This is because there is not enough documentation available for those versions. Users with files that old are kindly requested to export their projects to newer versions. In some cases it might also work to just replace AC1006 (or anything below AC1009) with AC1009 directly in the DXF.

===================================================================

M	io_import_dxf/__init__.py
M	io_import_dxf/dxfgrabber/headersection.py
M	io_import_dxf/dxfgrabber/sections.py

===================================================================

diff --git a/io_import_dxf/__init__.py b/io_import_dxf/__init__.py
index e3cfa99..fae5b17 100644
--- a/io_import_dxf/__init__.py
+++ b/io_import_dxf/__init__.py
@@ -22,6 +22,7 @@ import bpy
 import os
 from bpy.props import StringProperty, BoolProperty, EnumProperty, IntProperty, FloatProperty
 from .dxfimport.do import Do, Indicator
+from .dxfgrabber.headersection import MinVersionError
 from .transverse_mercator import TransverseMercator
 
 
@@ -109,17 +110,20 @@ def read(report, filename, obj_merge=BY_LAYER, import_text=True, import_light=Tr
          thicknessWidth=True, but_group_by_att=True, dxf_unit_scale=1.0):
     # import dxf and export nurbs types to sat/sab files
     # because that's how autocad stores nurbs types in a dxf...
-    do = Do(filename, obj_merge, import_text, import_light, export_acis, merge_lines, do_bbox, block_rep, recenter,
-            projDXF, projSCN, thicknessWidth, but_group_by_att, dxf_unit_scale)
-    errors = do.entities(os.path.basename(filename).replace(".dxf", ""), new_scene)
-
-    # display errors
-    for error in errors:
-        report('ERROR', error)
-
-    # inform the user about the sat/sab files
-    if len(do.acis_files) > 0:
-        report('INFO', "Exported %d NURBS objects to sat/sab files next to your DXF file" % len(do.acis_files))
+    try:
+        do = Do(filename, obj_merge, import_text, import_light, export_acis, merge_lines, do_bbox, block_rep, recenter,
+                projDXF, projSCN, thicknessWidth, but_group_by_att, dxf_unit_scale)
+        errors = do.entities(os.path.basename(filename).replace(".dxf", ""), new_scene)
+
+        # display errors
+        for error in errors:
+            report({'ERROR', 'INFO'}, error)
+
+        # inform the user about the sat/sab files
+        if len(do.acis_files) > 0:
+            report({'INFO'}, "Exported %d NURBS objects to sat/sab files next to your DXF file" % len(do.acis_files))
+    except MinVersionError as minv:
+        report({'ERROR', 'INFO'}, str(minv))
 
 
 def display_groups_in_outliner():
diff --git a/io_import_dxf/dxfgrabber/headersection.py b/io_import_dxf/dxfgrabber/headersection.py
index a12cee9..8c709a5 100755
--- a/io_import_dxf/dxfgrabber/headersection.py
+++ b/io_import_dxf/dxfgrabber/headersection.py
@@ -31,3 +31,9 @@ class HeaderSection(dict):
         groups = TagGroups(tags[2:-1], split_code=9)
         for group in groups:
             self[group[0].value] = group[1].value
+
+
+class MinVersionError(Exception):
+
+    def __init__(self, version):
+        Exception.__init__(self, "Minimum Version DXF12 (AC1009) not met. Version found: %s." % version)
diff --git a/io_import_dxf/dxfgrabber/sections.py b/io_import_dxf/dxfgrabber/sections.py
index 286ebf0..c1b0371 100755
--- a/io_import_dxf/dxfgrabber/sections.py
+++ b/io_import_dxf/dxfgrabber/sections.py
@@ -8,6 +8,7 @@ __author__ = "mozman <mozman at gmx.at>"
 from .codepage import toencoding
 from .defaultchunk import DefaultChunk, iterchunks
 from .headersection import HeaderSection
+from .headersection import MinVersionError
 from .tablessection import TablesSection
 from .entitysection import EntitySection, ObjectsSection
 from .blockssection import BlocksSection
@@ -29,6 +30,11 @@ class Sections(object):
             section = cls()
             self._sections[section.name] = section
 
+    def check_min_version(self, version_string):
+        v = int(version_string.replace("AC", ""))
+        if v < 1009:
+            raise MinVersionError(version_string)
+
     def _setup_sections(self, tagreader, drawing):
         def name(section):
             return section[1].value
@@ -38,6 +44,7 @@ class Sections(object):
             if bootstrap:
                 new_section = HeaderSection.from_tags(section)
                 drawing.dxfversion = new_section.get('$ACADVER', 'AC1009')
+                self.check_min_version(drawing.dxfversion)
                 codepage = new_section.get('$DWGCODEPAGE', 'ANSI_1252')
                 drawing.encoding = toencoding(codepage)
                 bootstrap = False



More information about the Bf-extensions-cvs mailing list