Polyline

The POLYLINE entity (POLYLINE DXF Reference) is very complex, it’s used to build 2D/3D polylines, 3D meshes and 3D polyfaces. For every type exists a different wrapper class but they all have the same dxftype of 'POLYLINE'. Detect POLYLINE type by Polyline.get_mode().

POLYLINE types returned by Polyline.get_mode():

For 2D entities all vertices in OCS.

For 3D entities all vertices in WCS.

Subclass of ezdxf.entities.DXFGraphic
DXF type 'POLYLINE'
2D factory function ezdxf.layouts.BaseLayout.add_polyline2d()
3D factory function ezdxf.layouts.BaseLayout.add_polyline3d()
Inherited DXF attributes Common graphical DXF attributes

Warning

Do not instantiate entity classes by yourself - always use the provided factory functions!

class ezdxf.entities.Polyline

Vertex entities are stored in a standard Python list Polyline.vertices. Vertices can be retrieved and deleted by direct access to Polyline.vertices attribute:

# delete first and second vertex
del polyline.vertices[:2]
dxf.elevation

Elevation point, the X and Y values are always 0, and the Z value is the polyline’s elevation (3D Point in OCS when 2D, WCS when 3D).

dxf.flags

Constants defined in ezdxf.lldxf.const:

Polyline.dxf.flags Value Description
POLYLINE_CLOSED 1 This is a closed Polyline (or a polygon mesh closed in the M direction)
POLYLINE_MESH_CLOSED_M_DIRECTION 1 equals POLYLINE_CLOSED
POLYLINE_CURVE_FIT_VERTICES_ADDED 2 Curve-fit vertices have been added
POLYLINE_SPLINE_FIT_VERTICES_ADDED 4 Spline-fit vertices have been added
POLYLINE_3D_POLYLINE 8 This is a 3D Polyline
POLYLINE_3D_POLYMESH 16 This is a 3D polygon mesh
POLYLINE_MESH_CLOSED_N_DIRECTION 32 The polygon mesh is closed in the N direction
POLYLINE_POLYFACE_MESH 64 This Polyline is a polyface mesh
POLYLINE_GENERATE_LINETYPE_PATTERN 128 The linetype pattern is generated continuously around the vertices of this Polyline
dxf.default_start_width

Default line start width (float); default = 0

dxf.default_end_width

Default line end width (float); default = 0

dxf.m_count

Polymesh M vertex count (int); default = 1

dxf.n_count

Polymesh N vertex count (int); default = 1

dxf.m_smooth_density

Smooth surface M density (int); default = 0

dxf.n_smooth_density

Smooth surface N density (int); default = 0

dxf.smooth_type

Curves and smooth surface type (int); default=0, see table below

Constants for smooth_type defined in ezdxf.lldxf.const:

Polyline.dxf.smooth_type Value Description
POLYMESH_NO_SMOOTH 0 no smooth surface fitted
POLYMESH_QUADRATIC_BSPLINE 5 quadratic B-spline surface
POLYMESH_CUBIC_BSPLINE 6 cubic B-spline surface
POLYMESH_BEZIER_SURFACE 8 Bezier surface
vertices

List of Vertex entities.

is_2d_polyline

True if POLYLINE is a 2D polyline.

is_3d_polyline

True if POLYLINE is a 3D polyline.

is_polygon_mesh

True if POLYLINE is a polygon mesh, see Polymesh

is_poly_face_mesh

True if POLYLINE is a poly face mesh, see Polyface

is_closed

True if POLYLINE is closed.

is_m_closed

True if POLYLINE (as Polymesh) is closed in m direction.

is_n_closed

True if POLYLINE (as Polymesh) is closed in n direction.

has_arc

Returns True if 2D POLYLINE has an arc segment.

has_width

Returns True if 2D POLYLINE has default width values or any segment with width attributes.

New in version 0.14.

get_mode() → str

Returns POLYLINE type as string:

  • ‘AcDb2dPolyline’
  • ‘AcDb3dPolyline’
  • ‘AcDbPolygonMesh’
  • ‘AcDbPolyFaceMesh’
m_close(status=True) → None

Close POLYMESH in m direction if status is True (also closes POLYLINE), clears closed state if status is False.

n_close(status=True) → None

Close POLYMESH in n direction if status is True, clears closed state if status is False.

close(m_close=True, n_close=False) → None

Set closed state of POLYMESH and POLYLINE in m direction and n direction. True set closed flag, False clears closed flag.

__len__() → int

Returns count of Vertex entities.

__getitem__(pos) → ezdxf.entities.polyline.DXFVertex

Get Vertex entity at position pos, supports list slicing.

points() → Iterator[ezdxf.math._vector.Vec3]

Returns iterable of all polyline vertices as (x, y, z) tuples, not as Vertex objects.

append_vertex(point: Union[Sequence[float], ezdxf.math._vector.Vec2, ezdxf.math._vector.Vec3], dxfattribs=None) → None

Append a single Vertex entity at location point.

Parameters:
  • point – as (x, y[, z]) tuple
  • dxfattribs – dict of DXF attributes for Vertex class
append_vertices(points: Iterable[Union[Sequence[float], ezdxf.math._vector.Vec2, ezdxf.math._vector.Vec3]], dxfattribs=None) → None

Append multiple Vertex entities at location points.

Parameters:
  • points – iterable of (x, y[, z]) tuples
  • dxfattribs – dict of DXF attributes for the VERTEX objects
append_formatted_vertices(points: Iterable[Union[Sequence[float], ezdxf.math._vector.Vec2, ezdxf.math._vector.Vec3]], format: str = 'xy', dxfattribs=None) → None

Append multiple Vertex entities at location points.

Parameters:
  • points – iterable of (x, y, [start_width, [end_width, [bulge]]]) tuple
  • format – format string, default is 'xy', see: User Defined Point Format Codes
  • dxfattribs – dict of DXF attributes for the VERTEX objects
insert_vertices(pos: int, points: Iterable[Union[Sequence[float], ezdxf.math._vector.Vec2, ezdxf.math._vector.Vec3]], dxfattribs=None) → None

Insert vertices points into Polyline.vertices list at insertion location pos .

Parameters:
  • pos – insertion position of list Polyline.vertices
  • points – list of (x, y[, z]) tuples
  • dxfattribs – dict of DXF attributes for Vertex class
transform(m: ezdxf.math._matrix44.Matrix44) → ezdxf.entities.polyline.Polyline

Transform the POLYLINE entity by transformation matrix m inplace.

A non-uniform scaling is not supported if a 2D POLYLINE contains circular arc segments (bulges).

Parameters:m – transformation Matrix44
Raises:NonUniformScalingError – for non-uniform scaling of 2D POLYLINE containing circular arc segments (bulges)
virtual_entities() → Iterator[Union[Line, Arc, Face3d]]

Yields the graphical representation of POLYLINE as virtual DXF primitives (LINE, ARC or 3DFACE).

These virtual entities are located at the original location, but are not stored in the entity database, have no handle and are not assigned to any layout.

explode(target_layout: BaseLayout = None) → EntityQuery

Explode the POLYLINE entity as DXF primitives (LINE, ARC or 3DFACE) into the target layout, if the target layout is None, the target layout is the layout of the POLYLINE entity.

Returns an EntityQuery container of all DXF primitives.

Parameters:target_layout – target layout for DXF primitives, None for same layout as source entity.

Vertex

A VERTEX (VERTEX DXF Reference) represents a polyline/mesh vertex.

Subclass of ezdxf.entities.DXFGraphic
DXF type 'VERTEX'
Factory function Polyline.append_vertex()
Factory function Polyline.extend()
Factory function Polyline.insert_vertices()
Inherited DXF Attributes Common graphical DXF attributes
class ezdxf.entities.Vertex
dxf.location

Vertex location (2D/3D Point OCS when 2D, WCS when 3D)

dxf.start_width

Line segment start width (float); default = 0

dxf.end_width

Line segment end width (float); default = 0

dxf.bulge

Bulge value (float); default = 0.

The bulge value is used to create arc shaped line segments.

dxf.flags

Constants defined in ezdxf.lldxf.const:

Vertex.dxf.flags Value Description
VTX_EXTRA_VERTEX_CREATED 1 Extra vertex created by curve-fitting
VTX_CURVE_FIT_TANGENT 2 curve-fit tangent defined for this vertex. A curve-fit tangent direction of 0 may be omitted from the DXF output, but is significant if this bit is set.
VTX_SPLINE_VERTEX_CREATED 8 spline vertex created by spline-fitting
VTX_SPLINE_FRAME_CONTROL_POINT 16 spline frame control point
VTX_3D_POLYLINE_VERTEX 32 3D polyline vertex
VTX_3D_POLYGON_MESH_VERTEX 64 3D polygon mesh
VTX_3D_POLYFACE_MESH_VERTEX 128 polyface mesh vertex
dxf.tangent

Curve fit tangent direction (float), used for 2D spline in DXF R12.

dxf.vtx1

Index of 1st vertex, if used as face (feature for experts)

dxf.vtx2

Index of 2nd vertex, if used as face (feature for experts)

dxf.vtx3

Index of 3rd vertex, if used as face (feature for experts)

dxf.vtx4

Index of 4th vertex, if used as face (feature for experts)

is_2d_polyline_vertex
is_3d_polyline_vertex
is_polygon_mesh_vertex
is_poly_face_mesh_vertex
is_face_record
format(format='xyz') → Sequence

Return formatted vertex components as tuple.

Format codes:

  • “x” = x-coordinate
  • “y” = y-coordinate
  • “z” = z-coordinate
  • “s” = start width
  • “e” = end width
  • “b” = bulge value
  • “v” = (x, y, z) as tuple
Args:
format: format string, default is “xyz”

New in version 0.14.

Polymesh

Subclass of ezdxf.entities.Polyline
DXF type 'POLYLINE'
Factory function ezdxf.layouts.BaseLayout.add_polymesh()
Inherited DXF Attributes Common graphical DXF attributes
class ezdxf.entities.Polymesh

A polymesh is a grid of m_count x n_count vertices, every vertex has its own (x, y, z) location. The Polymesh is an subclass of Polyline, DXF type is also 'POLYLINE' but get_mode() returns 'AcDbPolygonMesh'.

get_mesh_vertex(pos: Tuple[int, int]) → ezdxf.entities.polyline.DXFVertex

Get location of a single mesh vertex.

Parameters:pos – 0-based (row, col) tuple, position of mesh vertex
set_mesh_vertex(pos: Tuple[int, int], point: Union[Sequence[float], ezdxf.math._vector.Vec2, ezdxf.math._vector.Vec3], dxfattribs=None)

Set location and DXF attributes of a single mesh vertex.

Parameters:
  • pos – 0-based (row, col)-tuple, position of mesh vertex
  • point – (x, y, z)-tuple, new 3D coordinates of the mesh vertex
  • dxfattribs – dict of DXF attributes
get_mesh_vertex_cache() → ezdxf.entities.polyline.MeshVertexCache

Get a MeshVertexCache object for this POLYMESH. The caching object provides fast access to the location attribute of mesh vertices.

MeshVertexCache

class ezdxf.entities.MeshVertexCache

Cache mesh vertices in a dict, keys are 0-based (row, col) tuples.

Set vertex location: cache[row, col] = (x, y, z)

Get vertex location: x, y, z = cache[row, col]

vertices

Dict of mesh vertices, keys are 0-based (row, col) tuples.

__getitem__(pos: Tuple[int, int]) → Union[Sequence[float], ezdxf.math._vector.Vec2, ezdxf.math._vector.Vec3]

Get mesh vertex location as (x, y, z)-tuple.

Parameters:pos – 0-based (row, col)-tuple.
__setitem__(pos: Tuple[int, int], location: Union[Sequence[float], ezdxf.math._vector.Vec2, ezdxf.math._vector.Vec3]) → None

Get mesh vertex location as (x, y, z)-tuple.

Parameters:
  • pos – 0-based (row, col)-tuple.
  • location – (x, y, z)-tuple

Polyface

Subclass of ezdxf.entities.Polyline
DXF type 'POLYLINE'
Factory function ezdxf.layouts.BaseLayout.add_polyface()
Inherited DXF Attributes Common graphical DXF attributes
class ezdxf.entities.Polyface

A polyface consist of multiple location independent 3D areas called faces. The Polyface is a subclass of Polyline, DXF type is also 'POLYLINE' but get_mode() returns 'AcDbPolyFaceMesh'.

append_face(face: FaceType, dxfattribs=None) → None

Append a single face. A face is a list of (x, y, z) tuples.

Parameters:
  • face – List[(x, y, z) tuples]
  • dxfattribs – dict of DXF attributes for VERTEX objects
append_faces(faces: Iterable[FaceType], dxfattribs=None) → None

Append multiple faces. faces is a list of single faces and a single face is a list of (x, y, z) tuples.

Parameters:
  • faces – list of List[(x, y, z) tuples]
  • dxfattribs – dict of DXF attributes for teh VERTEX objects
faces() → Iterator[List[ezdxf.entities.polyline.DXFVertex]]

Iterable of all faces, a face is a tuple of vertices.

Returns:[vertex, vertex, vertex, [vertex,] face_record]
Return type:list
optimize(precision: int = 6) → None

Rebuilds Polyface including vertex optimization by merging vertices with nearly same vertex locations.

Parameters:precision – floating point precision for determining identical vertex locations