Skip to main content

A Python package to create/manipulate DXF drawings.

Project description

ezdxf

Abstract

A Python package to create and modify DXF drawings, independent from the DXF version. You can open/save every DXF file without losing any content (except comments), Unknown tags in the DXF file will be ignored but preserved for saving. With this behavior it is possible to open also DXF drawings that contains data from 3rd party applications.

Quick-Info

  • ezdxf is a Python package to create new DXF files and read/modify/write existing DXF files
  • the intended audience are developers
  • requires at least Python 3.6, for Python 3.5 use ezdxf < 0.11
  • OS independent
  • tested with CPython & PyPy on Windows 10 & Manjaro Linux
  • additional required packages: pyparsing
  • MIT-License
  • read/write/new support for DXF versions: R12, R2000, R2004, R2007, R2010, R2013 and R2018
  • additional read support for DXF versions R13/R14 (upgraded to R2000)
  • additional read support for older DXF versions than R12 (upgraded to R12)
  • preserves third-party DXF content
  • additional fast DXF R12 writer, that creates just an ENTITIES section with support for the basic DXF entities

A simple example:

import ezdxf

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

# Create new table entries (layers, linetypes, text styles, ...).
doc.layers.new('TEXTLAYER', dxfattribs={'color': 2})

# 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': 7})
msp.add_text(
    'Test', 
    dxfattribs={
        'layer': 'TEXTLAYER'
    }).set_pos((0, 0.2), align='CENTER')

# Save 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.r12writer 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

Install with pip for Python 3.6 and later:

pip install ezdxf

Install with pip for Python 3.5, this version will get critical bug fixes:

pip install ezdxf<0.11

Install latest development version with pip from GitHub:

pip install git+https://github.com/mozman/ezdxf.git@master

or from source:

python setup.py install

Website

https://ezdxf.mozman.at/

Documentation

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

Documentation of latest release at http://ezdxf.readthedocs.io/

Contribution

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

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

Feedback

Questions and feedback at Google Groups:

https://groups.google.com/d/forum/python-ezdxf

python-ezdxf@googlegroups.com

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

Contact

Please 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

News

Version 0.11b1 - dev

  • Using standard git branches:
    • master: development state
    • stable: latest stable release
  • Requires Python 3.6
  • NEW: Dimension.get_measurement() supports angular, angular3p and ordinate dimensions
  • NEW: Layout.add_radius_dim() implemented
  • NEW: shortcut calls Layout.add_radius_dim_2p() and Layout.add_radius_dim_cra()
  • NEW: Layout.add_diameter_dim() implemented
  • NEW: shortcut Layout.add_diameter_dim_2p()
  • NEW: Circle.vertices(angles) yields vertices for iterable angles in WCS
  • NEW: Ellipse.vertices(params) yields vertices for iterable params in WCS
  • NEW: Arc properties start_point and end_point returns start- and end point of arc in WCS
  • NEW: Ellipse properties start_point and end_point returns start- and end point of ellipse in WCS
  • NEW: Drawing.set_modelspace_vport(height, center) set initial view/zoom location for the modelspace
  • NEW: 2d construction function ezdxf.math.offset_vertices_2d()
  • NEW: Drawing.output_encoding returns required output encoding
  • NEW: User Coordinate System (UCS) based entity transformation, allows to work with UCS coordinates, which are simpler if the UCS is chosen wisely, and transform them later into WCS coordinates. Entities which have a transform_to_wcs(ucs) method, automatically take advantage of the new UCS transformation methods, but not all entity types are supported, embedded ACIS entities like 3DSOLID, REGION, SURFACE and so on, do not expose their geometry.
  • NEW: transform_to_wcs(ucs) implemented for: 3DFACE, ARC, ATTDEF, ATTRIB, CIRCLE, ELLIPSE, HATCH, IMAGE, INSERT, LEADER, LINE, LWPOLYLINE, MESH, MTEXT, POINT, POLYLINE, RAY, SHAPE, SOLID, SPLINE, TEXT, TRACE, XLINE
  • NEW: UCS.rotate(axis, angle) returns a new UCS rotated around WCS vector axis
  • NEW: UCS.rotate_local_x(angle) returns a new UCS rotated around local x-axis
  • NEW: UCS.rotate_local_y(angle) returns a new UCS rotated around local y-axis
  • NEW: UCS.rotate_local_z(angle) returns a new UCS rotated around local z-axis
  • NEW: UCS.copy() returns a new copy of UCS
  • NEW: UCS.shift(delta) shifts UCS inplace by vector delta
  • NEW: UCS.moveto(location) set new UCS origin to location inplace
  • NEW: load DXF comments from file (ezdxf.comments.from_file) or stream (ezdxf.comments.from_stream)
  • NEW: user defined point format support for 2d POLYLINE entities: add_polyline2d([(1, 2, 0.5), (3, 4, 0)], format='xyb')
  • NEW: Polyline.append_formatted_points() with user defined point format support
  • NEW: size and center properties for bounding box classes
  • NEW: Insert.ucs() returns an UCS placed in block reference insert location, UCS axis aligned to the block axis.
  • NEW: Insert.reset_transformation() reset block reference location, rotation and extrusion vector.
  • NEW: support for associating HATCH boundary paths to geometry entities
  • CHANGE: Changed predefined pattern scaling to BricsCAD and AutoCAD standard, set global option ezdxf.options.use_old_predefined_pattern_scaling to True, to use the old pattern scaling before v0.11
  • CHANGE: removed ezdxf.PATTERN constant, use PATTERN = ezdxf.pattern.load() instead, set argument old_pattern=True to use the old pattern scaling before v0.11
  • BUGFIX: fixed incorrect HATCH pattern scaling
  • BUGFIX: fixed base point calculation of aligned dimensions
  • BUGFIX: fixed length extension line support for linear dimensions
  • BUGFIX: UCS.to_ocs_angle_deg() and UCS.to_ocs_angle_rad()
  • BUGFIX: check for unsupported DXF versions at new()
  • BUGFIX: fixed dxf2src error for the HATCH entity
  • BUGFIX: left_of_line() algorithm was incorrect

Version 0.10.4 - 2020-01-31

  • BUGFIX: height group code (40) for TEXT, ATTRIB and ATTDEF is mandatory

Version 0.10.3 - 2020-01-29

  • BUGFIX: min DXF version for VISUALSTYLE object is R2000

Version 0.10.2 - 2019-10-05

  • NEW: Dimension.get_measurement() returns the actual dimension measurement in WCS units, no scaling applied; angular and ordinate dimension are not supported yet.
  • BUGFIX: ordinate dimension exports wrong feature location
  • BUGFIX: Hatch.set_pattern_fill() did not set pattern scale, angle and double values

Version 0.10.1 - 2019-09-07

  • BUGFIX: group code for header var $ACADMAINTVER is 90 for DXF R2018+ and 70 for previous DXF versions. This is a critical bug because AutoCAD 2012/2013 (and possibly earlier versions) will not open DXF files with the new group code 90 for header variable $ACADMAINTVER.

Version 0.10 - 2019-09-01

  • Release notes: https://ezdxf.mozman.at/release-v0-10.html
  • unified entity system for all DXF versions
  • saving as later DXF version than the source DXF version is possible, but maybe data loss if saving as an older DXF version than source DXF version (ezdxf is not a DXF converter)
  • templates no more needed and removed from package
  • CHANGE: DXFEntity
    • renamed DXFEntity.drawing to DXFEntity.doc
    • DXFEntity.get_xdata() keyword xdata_tag renamed to tags
    • DXFEntity.set_xdata() keyword xdata_tag renamed to tags
    • renamed DXFEntity.remove_reactor_handle() renamed to DXFEntity.discard_reactor_handle()
    • DXFEntity.get_extension_dict() returns ExtensionDict object instead of the raw DICTIONARY object
    • renamed DXFEntity.supports_dxf_attrib() to DXFEntity.is_supported_dxf_attrib()
    • renamed DXFEntity.dxf_attrib_exists() to DXFEntity.has_dxf_attrib()
  • CHANGE: Layer entity
    • removed Layer.dxf.line_weight as synonym for Layer.dxf.lineweight
    • renamed Layer.dxf.plot_style_name to Layer.dxf.plotstyle_handle
    • renamed Layer.dxf.material to Layer.dxf.material_handle
  • CHANGE: same treatment of Viewport entity for all DXF versions
  • CHANGE: Polyline.vertices() is now an attribute Polyline.vertices, implemented as regular Python list.
  • CHANGE: Insert.attribs() is now an attribute Insert.attribs, implemented as regular Python list.
  • CHANGE: renamed Viewport.dxf.center_point to Viewport.dxf.center
  • CHANGE: renamed Viewport.dxf.target_point to Viewport.dxf.target
  • CHANGE: direct access to hatch paths (Hatch.paths), pattern (Hatch.pattern) and gradient (Hatch.gradient), context manager to edit this data is not needed anymore, but still available for backward compatibility
  • CHANGE: Options
    • removed template_dir, no more needed
    • new log_unprocessed_tags to log unprocessed (unknown) DXF tags
  • CHANGE: Dimension() removes associated anonymous dimension block at deletion
  • CHANGE: safe block deletion protects not explicit referenced blocks like anonymous dimension blocks and arrow blocks
  • CHANGE: Importer add-on rewritten, API incompatible to previous ezdxf versions, but previous implementation was already broken
  • CHANGE: moved add_attdef() to generic layout interface, adding ATTDEF to model- and paperspace is possible
  • CHANGE: entity query - exclude DXF types from '*' search, by appending type name with a preceding '!' e.g. query for all entities except LINE = "* !LINE"
  • CHANGE: entity query - removed regular expression support for type name match
  • CHANGE: integration of MTextData methods into MText
  • CHANGE: removed edit_data, get_text, set_text methods from MText
  • restructured package, module and test file organization
  • NEW: support for Layer.dxf.true_color and Layer.dxf.transparency attributes (DXF R2004+, undocumented)
  • NEW: Layer.rgb, Layer.color, Layer.description and Layer.transparency properties
  • NEW: renaming a Layer also renames references to this layer, but use with care
  • NEW: support for adding LEADER entities
  • NEW: Dimension.get_geometry_block(), returns the associated anonymous dimension block or None
  • NEW: EntityQuery() got first and last properties, to get first or last entity or None if query result is empty
  • NEW: added ngon(), star() and gear() to ezdxf.render.forms
  • NEW: Source code generator to create Python source code from DXF entities, to recreate this entities by ezdxf. This tool creates only simple structures as a useful starting point for parametric DXF entity creation from existing DXF files. Not all DXF entities are supported!
  • NEW: support for named plot style files (STB)
  • NEW: can open converted Gerber DXF files tagged as "Version 1.0, Gerber Technology."
  • BUGFIX: fixed MTEXT and GEODATA text splitting errors (do not split at '^')
  • BUGFIX: fixed some subclass errors, mostly DXF reference errors
  • BUGFIX: VERTEX entity inherit owner and linetype attribute from POLYLINE entity
  • BUGFIX: MTEXT - replacement of \n by \P at DXF export to avoid invalid DXF files.
  • tested with CPython 3.8
  • removed batch files (.bat) for testing, use tox command instead

Version 0.9 - 2019-02-24

  • Release notes: https://ezdxf.mozman.at/release-v0-9.html
  • IMPORTANT: Python 2 support REMOVED, if Python 2 support needed: add ezdxf<0.9 to your requirements.txt
  • NEW: testing on Manjaro Linux in a VM by tox
  • CHANGE: converted NEWS.rst to NEWS.md and README.rst to README.md
  • CHANGE: moved Importer() from ezdxf.tools to ezdxf.addons - internal structures of modern DXF files are too complex and too undocumented to support importing data in a reliable way - using Importer() may corrupt your DXF files or just don't work!
  • NEW: type annotations to core package and add-ons.
  • NEW: argument setup in ezdxf.new('R12', setup=True) to setup default line types, text styles and dimension styles, this feature is disabled by default.
  • NEW: Duplicate table entries: dwg.styles.duplicate_entry('OpenSans', new_name='OpenSansNew'), this works for all tables, but is intended to duplicate STYLES and DIMSTYLES.
  • CHANGED: replaced proprietary fonts in style declarations by open source fonts
  • NEW: open source fonts to download https://github.com/mozman/ezdxf/tree/master/fonts
  • OpenSansCondensed-Light font used for default dimension styles
  • NEW: subpackage ezdxf.render, because of DIMENSION rendering
  • NEW: support for AutoCAD standard arrows
  • NEW: support for creating linear DIMENSION entities
  • NEW: background color support for MTEXT
  • CHANGE: DXF template cleanup, removed non standard text styles, dimension styles, layers and blocks
  • CHANGE: text style STANDARD uses txt font
  • CHANGE: renamed subpackage ezdxf.algebra to ezdxf.math
  • CHANGE: moved addons.curves to render.curves
  • CHANGE: moved addons.mesh to render.mesh
  • CHANGE: moved addons.r12spline to render.r12spline
  • CHANGE: moved addons.forms to render.forms
  • CHANGE: renamed construction helper classes into Construction...()
    • Ray2D() renamed to ConstructionRay()
    • Circle() renamed to ConstructionCircle()
    • Arc() renamed to ConstructionArc()
  • NEW: construction tools ConstructionLine() and ConstructionBox()
  • REMOVED: almost_equal use math.isclose
  • REMOVED: almost_equal_points use ezdxf.math.is_close_points
  • BUGFIX: closed LWPOLYLINE did not work in AutoCAD (tag order matters), introduced with v0.8.9 packed data structure
  • BUGFIX: UCS.to_ocs_angle_deg() corrected

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ezdxf-0.11b1.zip (816.4 kB view hashes)

Uploaded Source

Built Distribution

ezdxf-0.11b1-py3-none-any.whl (479.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page