mozman / ezdxf

Python interface to DXF
https://ezdxf.mozman.at
MIT License
935 stars 191 forks source link

ezdxf

Abstract

This Python package is designed to facilitate the creation and manipulation of DXF documents, with compatibility across various DXF versions. It empowers users to seamlessly load and edit DXF files while preserving all content, except for comments.

Any unfamiliar DXF tags encountered in the document are gracefully ignored but retained for future modifications. This feature enables the processing of DXF documents containing data from third-party applications without any loss of valuable information.

Quick-Info

Included Extensions

Additional packages required for these add-ons are not automatically installed during the basic setup, for more information about the setup & dependencies visit the documentation.

A simple example:

import ezdxf
from ezdxf import colors
from ezdxf.enums import TextEntityAlignment

# Create a new DXF document.
doc = ezdxf.new(dxfversion="R2010")

# Create new table entries (layers, linetypes, text styles, ...).
doc.layers.add("TEXTLAYER", color=colors.RED)

# DXF entities (LINE, TEXT, ...) reside in a layout (modelspace, 
# paperspace layout or block definition).  
msp = doc.modelspace()

# Add entities to a layout by factory methods: layout.add_...() 
msp.add_line((0, 0), (10, 0), dxfattribs={"color": colors.YELLOW})
msp.add_text(
    "Test", 
    dxfattribs={
        "layer": "TEXTLAYER"
    }).set_placement((0, 0.2), align=TextEntityAlignment.CENTER)

# Save the DXF document.
doc.saveas("test.dxf")

Example for the r12writer, which writes a simple DXF R12 file without in-memory structures:

from random import random
from ezdxf.addons import r12writer

MAX_X_COORD = 1000
MAX_Y_COORD = 1000

with r12writer("many_circles.dxf") as doc:
    for _ in range(100000):
        doc.add_circle((MAX_X_COORD*random(), MAX_Y_COORD*random()), radius=2)

The r12writer supports only the ENTITIES section of a DXF R12 drawing, no HEADER, TABLES or BLOCKS section is present, except FIXED-TABLES are written, than some additional predefined text styles and line types are available.

Installation

Basic installation by pip including the optional C-extensions from PyPI as binary wheels:

pip install ezdxf

Full installation with all dependencies (matplotlib, PySide6) for using the drawing add-on:

pip install ezdxf[draw]

For more information about the setup & dependencies visit the documentation.

Command Line

Use python -m ezdxf ... if your shell can't find the ezdxf script.

Get additional help for a sub-command:

ezdxf <cmd> -h

Preview DXF files in a graphical window:

ezdxf view <file.dxf>

Export the modelspace of DXF files as PNG|SVG|PDF:

ezdxf draw -o file.<png|svg|pdf> <file.dxf>

Print basic information about DXF files:

ezdxf info <file.dxf>

Show detailed information and structures of DXF files:

ezdxf browse <file.dxf>

Audit DXF files:

ezdxf audit <file.dxf>

Preview and convert HPGL/2 plot files:

ezdxf hpgl <file.plt>

Website

https://ezdxf.mozman.at/

Documentation

Documentation of the development version at https://ezdxf.mozman.at/docs

Documentation of the latest release at https://ezdxf.readthedocs.io/

Knowledge Graph

The knowledge graph contains additional information beyond the documentation and is managed by logseq. The source data is included in the repository in the folder ezdxf/notes. There is also a HTML export on the website which gets regular updates.

Contribution

The source code of ezdxf can be found at GitHub, target your pull requests to the master branch:

https://github.com/mozman/ezdxf.git

Feedback

Questions and feedback at GitHub Discussions:

https://github.com/mozman/ezdxf/discussions

Questions at Stack Overflow:

Post questions at stack overflow and use the tag dxf or ezdxf.

Issue tracker at GitHub:

http://github.com/mozman/ezdxf/issues

Release Notes

The release notes are included in the knowledge graph.

Changelog

The changelog is included in the knowledge graph.

Contact

Please always post questions at the forum or stack overflow to make answers available to other users as well.

ezdxf@mozman.at

Feedback is greatly appreciated.

Manfred