Page MenuHome

Error importing AutoCad DWG file
Closed, ArchivedPublic

Description

I am trying to use the AutoCAD import addon to import a DWG file, and this errors out with "UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 227: character maps to <undefined>".

I opened the dwg file in Notepad++ and I can see that the header starts with "AC1032" which is the latest version of DWG files.

The full system console output is:

Traceback (most recent call last):
  File "C:\Program Files\Blender Foundation\Blender 2.90\2.90\scripts\addons\io_import_dxf\dxfgrabber\__init__.py", line 43, in readfile
    return readfile_as_asc(filename, options)
  File "C:\Program Files\Blender Foundation\Blender 2.90\2.90\scripts\addons\io_import_dxf\dxfgrabber\__init__.py", line 58, in readfile_as_asc
    return _read_encoded_file(filename, options, encoding=get_encoding())
  File "C:\Program Files\Blender Foundation\Blender 2.90\2.90\scripts\addons\io_import_dxf\dxfgrabber\__init__.py", line 55, in get_encoding
    info = dxfinfo(fp)
  File "C:\Program Files\Blender Foundation\Blender 2.90\2.90\scripts\addons\io_import_dxf\dxfgrabber\tags.py", line 453, in dxfinfo
    tag = next(tagreader)
  File "C:\Program Files\Blender Foundation\Blender 2.90\2.90\scripts\addons\io_import_dxf\dxfgrabber\tags.py", line 151, in stream_tagger
    x = next_tag()
  File "C:\Program Files\Blender Foundation\Blender 2.90\2.90\scripts\addons\io_import_dxf\dxfgrabber\tags.py", line 137, in next_tag
    code = stream.readline()
  File "C:\Program Files\Blender Foundation\Blender 2.90\2.90\python\lib\encodings\cp1252.py", line 23, in decode
    return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 227: character maps to <undefined>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Program Files\Blender Foundation\Blender 2.90\2.90\scripts\addons\io_import_dxf\__init__.py", line 541, in execute
    proj_dxf, proj_scn, self.represent_thickness_and_width, self.import_atts, dxf_unit_scale)
  File "C:\Program Files\Blender Foundation\Blender 2.90\2.90\scripts\addons\io_import_dxf\__init__.py", line 117, in read
    projDXF, projSCN, thicknessWidth, but_group_by_att, dxf_unit_scale)
  File "C:\Program Files\Blender Foundation\Blender 2.90\2.90\scripts\addons\io_import_dxf\dxfimport\do.py", line 104, in __init__
    self.dwg = dxfgrabber.readfile(dxf_filename, {"assure_3d_coords": True})
  File "C:\Program Files\Blender Foundation\Blender 2.90\2.90\scripts\addons\io_import_dxf\dxfgrabber\__init__.py", line 45, in readfile
    return readfile_as_utf8(filename, options, errors='ignore')
  File "C:\Program Files\Blender Foundation\Blender 2.90\2.90\scripts\addons\io_import_dxf\dxfgrabber\__init__.py", line 49, in readfile_as_utf8
    return _read_encoded_file(filename, options, encoding='utf-8', errors=errors)
  File "C:\Program Files\Blender Foundation\Blender 2.90\2.90\scripts\addons\io_import_dxf\dxfgrabber\__init__.py", line 65, in _read_encoded_file
    dwg = Drawing(fp, options)
  File "C:\Program Files\Blender Foundation\Blender 2.90\2.90\scripts\addons\io_import_dxf\dxfgrabber\drawing.py", line 30, in __init__
    sections = Sections(tagreader, self)
  File "C:\Program Files\Blender Foundation\Blender 2.90\2.90\scripts\addons\io_import_dxf\dxfgrabber\sections.py", line 21, in __init__
    self._setup_sections(tagreader, drawing)
  File "C:\Program Files\Blender Foundation\Blender 2.90\2.90\scripts\addons\io_import_dxf\dxfgrabber\sections.py", line 36, in _setup_sections
    for section in iterchunks(tagreader, stoptag='EOF', endofchunk='ENDSEC'):
  File "C:\Program Files\Blender Foundation\Blender 2.90\2.90\scripts\addons\io_import_dxf\dxfgrabber\defaultchunk.py", line 27, in iterchunks
    tag = next(tagreader)
  File "C:\Program Files\Blender Foundation\Blender 2.90\2.90\scripts\addons\io_import_dxf\dxfgrabber\tags.py", line 151, in stream_tagger
    x = next_tag()
  File "C:\Program Files\Blender Foundation\Blender 2.90\2.90\scripts\addons\io_import_dxf\dxfgrabber\tags.py", line 141, in next_tag
    return DXFTag(int(code.rstrip('\r\n')), value.rstrip('\r\n'))  # without line ending
ValueError: invalid literal for int() with base 10: 'AC1032\x00\x00\x00\x00\x00\x00\x03\x01\x00\x00!\x00\x1e\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x01\x00\x00\x00\x00\x00\x00\x00\x00\x00'

Event Timeline

Omar Emara (OmarSquircleArt) changed the task status from Needs Triage to Needs Information from User.Mar 23 2022, 12:53 PM

Can you attach the file in question for us to take a look? Seems to be an issue in the parser as opposed to the add-on.

I am not sure about uploading the drawing here, because I don't own it.
One further information though, is that I had the architect export the drawing in DXF format instead of DWG and that did import into Blender successfully.
I am now not very sure whether Blender is even supposed to be able to import DWG files.

Ah, that explains it then, I didn't realize DWG was a different format. Unfortunately, the add-on can't import this format, so you will have to convert to DXF first.