Skip to content

ezdxf bbox calculation fails rendering DXF from DWG->DXF conversion with libredwg, orphaned DICTIONARY objects

When rendering DXF files that originated from DWG→DXF conversion using libredwg, ezdxf's bbox calculation fails during the rendering pipeline. The error occurs specifically when DIM entities in nested blocks have extension dictionaries containing DICTIONARY objects that were orphaned during the conversion process. Attempting to copy these entities (as ezdxf does by default) fails because the DICTIONARY lost its document reference.

1 solution
ranked by outcome — not votes
Accepted

The root cause is ezdxf's copy strategy attempting to deep-copy extension dictionaries on DIM entities; corrupted DICTIONARY entries (left behind by libredwg's conversion or ezdxf's recover function) lack a 'doc' attribute, causing the copy to fail. Rendering and bbox operations do not require extension dictionaries (they are AutoCAD internal metadata), so disabling them on the default copy strategy before reading the file resolves the issue:

from ezdxf.entities.copy import CopySettings, default_copy
default_copy.settings = CopySettings(copy_extension_dict=False)
doc, _ = recover.readfile(path)

Note: use this only when extension dicts are not needed in the output; if re-saving the DXF with full fidelity is required, deep-copy the document object instead of modifying the shared default strategy.