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 

DXF type 

2D factory function 

3D factory function 

Inherited 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 listPolyline.vertices
. Vertices can be retrieved and deleted by direct access toPolyline.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
: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
Curvefit vertices have been added
POLYLINE_SPLINE_FIT_VERTICES_ADDED
4
Splinefit 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 inezdxf.lldxf.const
:Value
Description
POLYMESH_NO_SMOOTH
0
no smooth surface fitted
POLYMESH_QUADRATIC_BSPLINE
5
quadratic Bspline surface
POLYMESH_CUBIC_BSPLINE
6
cubic Bspline surface
POLYMESH_BEZIER_SURFACE
8
Bezier surface
 is_2d_polyline¶
True
if POLYLINE is a 2D polyline.
 is_3d_polyline¶
True
if POLYLINE is a 3D polyline.
 is_closed¶
True
if POLYLINE is closed.
 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.
 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 isFalse
.
 n_close(status=True) None ¶
Close POLYMESH in n direction if status is
True
, clears closed state if status isFalse
.
 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.
 points() Iterator[Vec3] ¶
Returns iterable of all polyline vertices as
(x, y, z)
tuples, not asVertex
objects.
 append_vertex(point: Union[Sequence[float], Vec2, Vec3], dxfattribs=None) None ¶
Append a single
Vertex
entity at location point. Parameters
point – as
(x, y[, z])
tupledxfattribs – dict of DXF attributes for
Vertex
class
 append_vertices(points: Iterable[Union[Sequence[float], Vec2, Vec3]], dxfattribs=None) None ¶
Append multiple
Vertex
entities at location points. Parameters
points – iterable of
(x, y[, z])
tuplesdxfattribs – dict of DXF attributes for the VERTEX objects
 append_formatted_vertices(points: Iterable[Union[Sequence[float], Vec2, 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 Codesdxfattribs – dict of DXF attributes for the VERTEX objects
 insert_vertices(pos: int, points: Iterable[Union[Sequence[float], Vec2, 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])
tuplesdxfattribs – dict of DXF attributes for
Vertex
class
 transform(m: Matrix44) Polyline ¶
Transform the POLYLINE entity by transformation matrix m inplace.
A nonuniform scaling is not supported if a 2D POLYLINE contains circular arc segments (bulges).
 Parameters
m – transformation
Matrix44
 Raises
NonUniformScalingError – for nonuniform 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: Optional[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 

DXF type 

Factory function 

Factory function 

Factory function 

Inherited DXF Attributes 
 class ezdxf.entities.Vertex¶

 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 curvefitting
VTX_CURVE_FIT_TANGENT
2
curvefit tangent defined for this vertex. A curvefit 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 splinefitting
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” = xcoordinate
“y” = ycoordinate
“z” = zcoordinate
“s” = start width
“e” = end width
“b” = bulge value
“v” = (x, y, z) as tuple
 Args:
format: format string, default is “xyz”
Polymesh¶
Subclass of 

DXF type 

Factory function 

Inherited DXF Attributes 
 class ezdxf.entities.Polymesh¶
A polymesh is a grid of
m_count
xn_count
vertices, every vertex has its own(x, y, z)
location. ThePolymesh
is an subclass ofPolyline
, DXF type is also'POLYLINE'
butget_mode()
returns'AcDbPolygonMesh'
. get_mesh_vertex(pos: tuple[int, int]) DXFVertex ¶
Get location of a single mesh vertex.
 Parameters
pos – 0based
(row, col)
tuple, position of mesh vertex
 set_mesh_vertex(pos: tuple[int, int], point: Union[Sequence[float], Vec2, Vec3], dxfattribs=None)¶
Set location and DXF attributes of a single mesh vertex.
 Parameters
pos – 0based (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() MeshVertexCache ¶
Get a
MeshVertexCache
object for this POLYMESH. The caching object provides fast access to thelocation
attribute of mesh vertices.
MeshVertexCache¶
 class ezdxf.entities.MeshVertexCache¶
Cache mesh vertices in a dict, keys are 0based
(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 0based
(row, col)
tuples.
Polyface¶
Subclass of 

DXF type 

Factory function 

Inherited DXF Attributes 
See also
 class ezdxf.entities.Polyface¶
A polyface consist of multiple location independent 3D areas called faces. The
Polyface
is a subclass ofPolyline
, DXF type is also'POLYLINE'
butget_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 the 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