A comprehensive Python package for creating, reading, modifying, and writing DXF (Drawing Exchange Format) documents with support for multiple DXF versions.
—
Complete set of entity classes for all DXF entity types, from basic geometric primitives to complex specialized entities. All entities inherit from base classes that provide common functionality for attribute management, transformation, and layout placement.
Fundamental 2D and 3D geometric primitives that form the building blocks of CAD drawings.
class Line(DXFGraphic):
"""Line entity connecting two points"""
@property
def start(self) -> Vec3:
"""Start point of line"""
@property
def end(self) -> Vec3:
"""End point of line"""
def transform(self, matrix: Matrix44): ...
class Point(DXFGraphic):
"""Point entity with location and optional thickness"""
@property
def location(self) -> Vec3:
"""Point location"""
class Circle(DXFGraphic):
"""Circle entity with center and radius"""
@property
def center(self) -> Vec3:
"""Circle center point"""
@property
def radius(self) -> float:
"""Circle radius"""
class Arc(DXFGraphic):
"""Circular arc entity"""
@property
def center(self) -> Vec3:
"""Arc center point"""
@property
def radius(self) -> float:
"""Arc radius"""
@property
def start_angle(self) -> float:
"""Start angle in degrees"""
@property
def end_angle(self) -> float:
"""End angle in degrees"""Usage examples:
import ezdxf
from ezdxf.math import Vec3
doc = ezdxf.new()
msp = doc.modelspace()
# Create basic entities
line = msp.add_line(start=(0, 0), end=(10, 5))
circle = msp.add_circle(center=(5, 5), radius=2.5)
arc = msp.add_arc(center=(0, 0), radius=3, start_angle=0, end_angle=90)
# Access and modify properties
print(f"Line length: {line.start.distance(line.end)}")
circle.radius = 3.0
arc.end_angle = 180Text rendering entities supporting single-line and multi-line text with rich formatting capabilities.
class Text(DXFGraphic):
"""Single-line text entity"""
@property
def text(self) -> str:
"""Text content"""
@property
def insert(self) -> Vec3:
"""Text insertion point"""
@property
def height(self) -> float:
"""Text height"""
def set_placement(self, insert: Vec3, align: str = None): ...
class MText(DXFGraphic):
"""Multi-line text entity with rich formatting"""
@property
def text(self) -> str:
"""Raw MTEXT content with formatting codes"""
@property
def insert(self) -> Vec3:
"""Text insertion point"""
@property
def char_height(self) -> float:
"""Character height"""
@property
def width(self) -> float:
"""Text box width"""
def plain_text(self) -> str:
"""Get text content without formatting codes"""Usage examples:
# Single-line text
text = msp.add_text("Hello World", height=2.5)
text.set_placement((10, 10))
# Multi-line text with formatting
mtext_content = "{\\fArial|b1|i1;Bold Italic Arial}\\P{\\fTimes;Regular Times}"
mtext = msp.add_mtext(mtext_content, dxfattribs={
'char_height': 2.0,
'width': 50.0
})Linear entities composed of multiple connected segments, supporting 2D/3D polylines with optional bulge values for arc segments.
class Polyline(DXFGraphic):
"""2D/3D polyline with vertices and optional bulge values"""
def append_vertex(self, location, dxfattribs: dict = None): ...
def insert_vertex(self, index: int, location, dxfattribs: dict = None): ...
def delete_vertex(self, index: int): ...
@property
def vertices(self):
"""Vertex entities"""
@property
def is_closed(self) -> bool:
"""True if polyline is closed"""
class LWPolyline(DXFGraphic):
"""Lightweight 2D polyline (optimized format)"""
def append(self, point, format: str = 'xyseb'): ...
def insert(self, index: int, point, format: str = 'xyseb'): ...
def __delitem__(self, index: int): ...
@property
def vertices(self) -> List:
"""List of vertex data (x, y, start_width, end_width, bulge)"""
@property
def is_closed(self) -> bool:
"""True if polyline is closed"""Usage examples:
from ezdxf.math import Vec3
# 3D polyline
points_3d = [Vec3(0, 0, 0), Vec3(10, 0, 5), Vec3(10, 10, 5), Vec3(0, 10, 0)]
polyline_3d = msp.add_polyline3d(points_3d)
polyline_3d.close() # Close the polyline
# Lightweight 2D polyline with bulge (arc segment)
lwpolyline = msp.add_lwpolyline([(0, 0), (10, 0), (10, 10)])
lwpolyline.append((0, 10), format='xyb') # Add point with bulge
lwpolyline.close()Sophisticated curve entities including ellipses, splines, and infinite lines.
class Ellipse(DXFGraphic):
"""Ellipse entity with center, major/minor axes"""
@property
def center(self) -> Vec3:
"""Ellipse center"""
@property
def major_axis(self) -> Vec3:
"""Major axis vector"""
@property
def minor_axis(self) -> Vec3:
"""Minor axis vector"""
@property
def ratio(self) -> float:
"""Minor to major axis ratio"""
class Spline(DXFGraphic):
"""NURBS spline curve"""
@property
def degree(self) -> int:
"""Spline degree"""
@property
def control_points(self) -> List[Vec3]:
"""Control point coordinates"""
@property
def knots(self) -> List[float]:
"""Knot vector"""
@property
def weights(self) -> List[float]:
"""Control point weights (for rational splines)"""
class XLine(DXFGraphic):
"""Infinite line (construction line)"""
@property
def start(self) -> Vec3:
"""Point on the line"""
@property
def unit_vector(self) -> Vec3:
"""Unit direction vector"""
class Ray(DXFGraphic):
"""Ray (semi-infinite line)"""
@property
def start(self) -> Vec3:
"""Ray start point"""
@property
def unit_vector(self) -> Vec3:
"""Unit direction vector"""Complex fill entities supporting patterns, solid fills, and gradient fills with boundary path definitions.
class Hatch(DXFGraphic):
"""Hatch entity with boundary paths and fill patterns"""
@property
def pattern_name(self) -> str:
"""Hatch pattern name"""
@property
def solid_fill(self) -> bool:
"""True if solid fill"""
@property
def pattern_type(self) -> int:
"""Pattern type (0=user, 1=predefined, 2=custom)"""
@property
def paths(self):
"""Boundary path definitions"""
@property
def gradient(self):
"""Gradient fill definition"""
def set_solid_fill(self, color: int = 256): ...
def set_pattern_fill(self, name: str, color: int = 256, angle: float = 0, scale: float = 1): ...
def set_gradient(self, color1: int, color2: int, rotation: float = 0): ...
class MPolygon(DXFGraphic):
"""Multi-polygon entity with holes and islands"""
@property
def paths(self):
"""Polygon boundary paths"""
@property
def fill_color(self) -> int:
"""Fill color index"""Block definition and insertion entities for reusable content and hierarchical drawing organization.
class Insert(DXFGraphic):
"""Block reference (insertion) entity"""
@property
def name(self) -> str:
"""Block name"""
@property
def insert(self) -> Vec3:
"""Insertion point"""
@property
def xscale(self) -> float:
"""X-axis scale factor"""
@property
def yscale(self) -> float:
"""Y-axis scale factor"""
@property
def zscale(self) -> float:
"""Z-axis scale factor"""
@property
def rotation(self) -> float:
"""Rotation angle in degrees"""
def explode(self) -> List[DXFEntity]:
"""Explode block insert into individual entities"""
class Block(DXFEntity):
"""Block definition start marker"""
@property
def name(self) -> str:
"""Block name"""
@property
def base_point(self) -> Vec3:
"""Block base point"""
class EndBlk(DXFEntity):
"""Block definition end marker"""Comprehensive dimensioning entities for annotating drawings with measurements and geometric relationships.
class Dimension(DXFGraphic):
"""Base class for dimension entities"""
@property
def dimstyle(self) -> str:
"""Dimension style name"""
@property
def actual_measurement(self) -> float:
"""Actual measured value"""
def render(self) -> List[DXFEntity]:
"""Render dimension to basic entities"""
# Specific dimension types inherit from Dimension
class LinearDimension(Dimension): ...
class AlignedDimension(Dimension): ...
class AngularDimension(Dimension): ...
class RadialDimension(Dimension): ...
class DiametricDimension(Dimension): ...
class OrdinateDimension(Dimension): ...Advanced 3D modeling entities including ACIS solids and parametric surfaces.
class Solid3d(DXFGraphic):
"""3D solid entity (ACIS-based)"""
@property
def acis_data(self) -> bytes:
"""ACIS solid data"""
class Surface(DXFGraphic):
"""3D surface entity"""
@property
def u_isolines(self) -> int:
"""Number of U-direction isolines"""
@property
def v_isolines(self) -> int:
"""Number of V-direction isolines"""
class Mesh(DXFGraphic):
"""Subdivision mesh entity"""
@property
def vertices(self) -> List[Vec3]:
"""Mesh vertex coordinates"""
@property
def faces(self) -> List[List[int]]:
"""Face definitions as vertex indices"""
@property
def edges(self) -> List[List[int]]:
"""Edge definitions as vertex index pairs"""class DXFEntity:
"""Base class for all DXF entities"""
@property
def dxftype(self) -> str:
"""DXF entity type name"""
@property
def handle(self) -> str:
"""Unique entity handle"""
@property
def owner(self) -> str:
"""Handle of owning object"""
def destroy(self): ...
def copy(self) -> 'DXFEntity': ...
class DXFGraphic(DXFEntity):
"""Base class for graphical entities that can be placed in layouts"""
@property
def layer(self) -> str:
"""Entity layer name"""
@property
def color(self) -> int:
"""Entity color (ACI or RGB)"""
@property
def linetype(self) -> str:
"""Entity linetype name"""
@property
def lineweight(self) -> int:
"""Entity lineweight"""
def transform(self, matrix: Matrix44): ...
def translate(self, dx: float, dy: float, dz: float): ...
def scale(self, sx: float, sy: float, sz: float): ...
def rotate_axis(self, axis: Vec3, angle: float): ...
class DXFObject(DXFEntity):
"""Base class for non-graphical DXF objects"""Layout classes provide factory methods for creating and adding entities:
# These methods are available on Layout, Modelspace, and Paperspace classes
def add_line(self, start, end, dxfattribs: dict = None) -> Line: ...
def add_circle(self, center, radius: float, dxfattribs: dict = None) -> Circle: ...
def add_arc(self, center, radius: float, start_angle: float, end_angle: float,
dxfattribs: dict = None) -> Arc: ...
def add_text(self, text: str, dxfattribs: dict = None) -> Text: ...
def add_mtext(self, text: str, dxfattribs: dict = None) -> MText: ...
def add_lwpolyline(self, points, format: str = 'xy', dxfattribs: dict = None) -> LWPolyline: ...
def add_polyline3d(self, points, dxfattribs: dict = None) -> Polyline: ...
def add_ellipse(self, center, major_axis, ratio: float = 1, start_param: float = 0,
end_param: float = 2*pi, dxfattribs: dict = None) -> Ellipse: ...
def add_spline(self, control_points, degree: int = 3, dxfattribs: dict = None) -> Spline: ...
def add_hatch(self, color: int = 256, dxfattribs: dict = None) -> Hatch: ...
def add_insert(self, name: str, insert = (0, 0), dxfattribs: dict = None) -> Insert: ...Install with Tessl CLI
npx tessl i tessl/pypi-ezdxf