From 68e4b7e6bf9ddd643bd8ac9b48b8b9aeaeae4b03 Mon Sep 17 00:00:00 2001 From: Lukas Treyer Date: Tue, 21 Oct 2014 16:37:45 +0200 Subject: 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. --- io_import_dxf/__init__.py | 26 +++++++++++++++----------- io_import_dxf/dxfgrabber/headersection.py | 6 ++++++ io_import_dxf/dxfgrabber/sections.py | 7 +++++++ 3 files changed, 28 insertions(+), 11 deletions(-) (limited to 'io_import_dxf') diff --git a/io_import_dxf/__init__.py b/io_import_dxf/__init__.py index e3cfa99b..fae5b173 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 a12cee95..8c709a5e 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 286ebf09..c1b03714 100755 --- a/io_import_dxf/dxfgrabber/sections.py +++ b/io_import_dxf/dxfgrabber/sections.py @@ -8,6 +8,7 @@ __author__ = "mozman " 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 -- cgit v1.2.3