Create New Drawings¶
Create a new drawing from a template-drawing. The template-drawings are located in a template directory, which resides by default in the ezdxf package subfolder templates. The location of the template directory can be changed by the global option
ezdxf.options.template_dir. dxfversion can be either
'AC1009'the official DXF version name or
'R12'the AutoCAD release name (release name works since ezdxf 0.7.4). You can only create new drawings for the following DXF versions:
You can open DXF drawings from disk or from a text-stream. (byte-stream usage is not implemented yet).
readfile(filename, encoding='auto', legacy_mode=False)¶
This is the preferred method to open existing DXF files. Read the DXF drawing from the file-system with auto-detection of encoding. Decoding errors will be ignored. Override encoding detection by setting parameter encoding to the estimated encoding. (use Python encoding names like in the
If parameter legacy_mode is True, ezdxf tries to reorder the coordinates of the LINE entity in DXF files from CAD applications which wrote the coordinates in the order: x1, x2, y1, y2. Additional fixes may be added later. The legacy mode has a speed penalty of around 5%.
Try option legacy_mode=True if error “Missing required y coordinate near line: …” occurs.
Read DXF drawing from a text-stream, returns a
Drawingobject. Open the stream in text mode (mode=’rt’) and the correct encoding has to be set at the open function (in Python 2.7 use
io.open()), the stream requires at least a
readline()method. Since DXF version R2007 (AC1021) file encoding is always ‘utf-8’.
If parameter legacy_mode is True, ezdxf tries to reorder the coordinates of the LINE entity in DXF files from CAD applications which wrote the coordinates in the order: x1, x2, y1, y2, see also
Global options stored in
If you don’t need access to binary data of DXF entities, you can compress them in memory for a lower memory footprint, set the global
ezdxf.options.compress_binary_data = Trueto compress binray data for every drawing you open, but data compression cost time, so this option isn’t active by default. You can individually compress the binary data of a drawing with the method
Directory where the
new()function looks for its template file (AC1009.dxf, AC1015.dxf, …) , default is None, which means the package subfolder templates. But if you want to use your own templates set this option
ezdxf.options.template_dir = "my_template_directory". But you don’t really need this, just open your template file with
ezdxf.readfile()and save the drawing as new file with the
This option is very useful if the ezdxf package resides in a zip archive.