99from ezdxf .document import Drawing
1010from ezdxf .sections .table import Table
1111
12- __all__ = ["translate_names" , "purify " , "R12NameTranslator" ]
12+ __all__ = ["translate_names" , "clean " , "R12NameTranslator" ]
1313
1414
1515def translate_names (doc : Drawing ) -> None :
@@ -35,15 +35,41 @@ def translate_names(doc: Drawing) -> None:
3535 _R12StrictRename (doc ).execute ()
3636
3737
38- def purify (doc : Drawing ) -> None :
39- """Remove or destroy all features and entity types that are not supported by DXF
40- version R12 .
38+ def clean (doc : Drawing ) -> None :
39+ """Remove all features that are not supported for DXF version R12 by Autodesk
40+ products .
4141 """
4242 if doc .dxfversion != const .DXF12 :
4343 raise const .DXFVersionError (
4444 f"expected DXF document version R12, got: { doc .acad_release } "
4545 )
46- raise NotImplementedError ()
46+ _remove_table_xdata (doc .appids )
47+ _remove_table_xdata (doc .linetypes )
48+ _remove_table_xdata (doc .layers )
49+ _remove_table_xdata (doc .styles )
50+ _remove_table_xdata (doc .dimstyles )
51+ _remove_table_xdata (doc .ucs )
52+ _remove_table_xdata (doc .views )
53+ _remove_table_xdata (doc .viewports )
54+ _remove_legacy_blocks (doc )
55+
56+
57+ def _remove_table_xdata (table : Table ) -> None :
58+ """Autodesk products do not accept XDATA in table entries for DXF R12."""
59+ for entry in list (table ):
60+ entry .xdata = None
61+
62+
63+ def _remove_legacy_blocks (doc : Drawing ) -> None :
64+ """Due to bad conversion some DXF files contain after loading the blocks
65+ "$MODEL_SPACE" and "$PAPER_SPACE", delete them (no content) because they will
66+ clash with the translated layout names of "*Model_Space" and "*Paper_Space".
67+ """
68+ for name in ("$MODEL_SPACE" , "$PAPER_SPACE" ):
69+ try :
70+ doc .blocks .delete_block (name , safe = False )
71+ except const .DXFKeyError :
72+ pass
4773
4874
4975class R12NameTranslator :
0 commit comments