R12 Export

Added in version 1.1.

This module exports any DXF file as a simple DXF R12 file. Many complex entities will be converted into DXF primitives. This exporter is intended for creating a simple file format as an input format for other software such as laser cutters. In order to get a file that can be edited well in a CAD application, the results of the ODA file converter are much better.

Usage

import ezdxf
from ezdxf.addons import r12export

doc = ezdxf.readfile("any.dxf")
r12export.saveas(doc, "r12.dxf")

Converted Entity Types

LWPOLYLINE

translated to POLYLINE

MESH

translated to POLYLINE (PolyfaceMesh)

SPLINE

flattened to POLYLINE

ELLIPSE

flattened to POLYLINE

MTEXT

exploded into DXF primitives

LEADER

exploded into DXF primitives

MLEADER

exploded into DXF primitives

MULTILEADER

exploded into DXF primitives

MLINE

exploded into DXF primitives

HATCH

exploded into DXF primitives

MPOLYGON

exploded into DXF primitives

ACAD_TABLE

export of pre-rendered BLOCK content

For proxy- or unknown entities the available proxy graphic will be exported as DXF primitives.

Limitations

  • Explosion of MTEXT into DXF primitives is not perfect

  • Pattern rendering for complex HATCH entities has issues

  • Solid fill rendering for complex HATCH entities has issues

ODA File Converter

The advantage of the r12export module is that the ODA file converter isn’t needed, but the ODA file converter will produce a much better result:

from ezdxf.addons import odafc

odafc.convert("any.dxf", "r12.dxf", version="R12")

Functions

write

Write a DXF document as DXF version R12 to a text stream.

saveas

Write a DXF document as DXF version R12 to a file.

convert

Export and reload DXF document as DXF version R12.

ezdxf.addons.r12export.write(doc: Drawing, stream: TextIO, *, max_sagitta: float = MAX_SAGITTA) None

Write a DXF document as DXF version R12 to a text stream. The max_sagitta argument determines the accuracy of the curve flatting for SPLINE and ELLIPSE entities.

Parameters:
  • doc – DXF document to export

  • stream – output stream, use doc.encoding as encoding

  • max_sagitta – maximum distance from the center of the curve to the center of the line segment between two approximation points to determine if a segment should be subdivided.

ezdxf.addons.r12export.saveas(doc: Drawing, filepath: str | PathLike, *, max_sagitta: float = MAX_SAGITTA) None

Write a DXF document as DXF version R12 to a file. The max_sagitta argument determines the accuracy of the curve flatting for SPLINE and ELLIPSE entities.

Parameters:
  • doc – DXF document to export

  • filepath – output filename

  • max_sagitta – maximum distance from the center of the curve to the center of the line segment between two approximation points to determine if a segment should be subdivided.

ezdxf.addons.r12export.convert(doc: Drawing, *, max_sagitta: float = MAX_SAGITTA) Drawing

Export and reload DXF document as DXF version R12.

Writes the DXF document into a temporary file at the file-system and reloads this file by the ezdxf.readfile() function.