Polyline¶

class
Polyline
(GraphicEntity)¶
The POLYLINE entity 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 the polyline type by
Polyline.get_mode()
.
Create 2D polylines in layouts and blocks by factory function add_polyline2D()
.
For 2D entities all points in OCS.
Create 3D polylines in layouts and blocks by factory function add_polyline3D()
.
For 3D entities all points in WCS.
DXF Attributes for Polyline¶
Common DXF Attributes for DXF R12
Common DXF Attributes for DXF R13 or later

Polyline.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).

Polyline.dxf.
flags
¶
Constants defined in ezdxf.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  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 

Polyline.dxf.
default_start_width
¶
Default line start width (float); default=0

Polyline.dxf.
default_end_width
¶
Default line end width (float); default=0

Polyline.dxf.
m_count
¶
Polymesh M vertex count (int); default=1

Polyline.dxf.
n_count
¶
Polymesh N vertex count (int); default=1

Polyline.dxf.
m_smooth_density
¶
Smooth surface M density (int); default=0

Polyline.dxf.
n_smooth_density
¶
Smooth surface N density (int); default=0

Polyline.dxf.
smooth_type
¶
Curves and smooth surface type (int); default=0, see table below
Constants for smooth_type defined in ezdxf.const
:
Polyline.dxf.smooth_type  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 
Polyline Attributes¶

Polyline.
is_2d_polyline
¶
True if polyline is a 2D polyline.

Polyline.
is_3d_polyline
¶
True if polyline is a 3D polyline.

Polyline.
is_polygon_mesh
¶
True if polyline is a polygon mesh, see Polymesh

Polyline.
is_poly_face_mesh
¶
True if polyline is a poly face mesh, see Polyface

Polyline.
is_closed
¶
True if polyline is closed.

Polyline.
is_m_closed
¶
True if polyline (as polymesh) is closed in m direction.

Polyline.
is_n_closed
¶
True if polyline (as polymesh) is closed in n direction.
Polyline Methods¶

Polyline.
get_mode
()¶
Returns a string: AcDb2dPolyline
, AcDb3dPolyline
, AcDbPolygonMesh
or AcDbPolyFaceMesh

Polyline.
m_close
()¶
Close mesh in M direction (also closes polylines).

Polyline.
n_close
()¶
Close mesh in N direction.

Polyline.
close
(m_close, n_close=False)¶
Close mesh in M (if mclose is True) and/or N (if nclose is True) direction.

Polyline.
__len__
()¶
Returns count of vertices.

Polyline.
__getitem__
(pos)¶
Get Vertex
object at position pos. Very slow!!!. Vertices are organized as linked list, so it is
faster to work with a temporary list of vertices: list(polyline.vertices())
.

Polyline.
vertices
()¶
Iterate over all polyline vertices as Vertex
objects. (replaces Polyline.__iter__()
)

Polyline.
points
()¶
Iterate over all polyline points as (x, y[, z])tuples, not as Vertex
objects.

Polyline.
append_vertices
(points, dxfattribs=None)¶
Append points as Vertex
objects.
param points:  iterable polyline points, every point is a (x, y[, z])tuple. 

param dxfattribs:  
dict of DXF attributes for the Vertex 

Polyline.
insert_vertices
(pos, points, dxfattribs=None)¶
Insert points as Vertex
objects at position pos.
param int pos:  0based insert position 

param iterable points:  
iterable polyline points, every point is a tuple.  
param dxfattribs:  
dict of DXF attributes for the Vertex 

Polyline.
delete_vertices
(pos, count=1)¶
Delete count vertices at position pos.
param int pos:  0based insert position 

param int count:  
count of vertices to delete 
Vertex¶

class
Vertex
(GraphicEntity)¶ A vertex represents a polyline/mesh point, dxftype is
VERTEX
, you don’t have to create vertices by yourself.
DXF Attributes for Vertex¶

Vertex.dxf.
location
¶
vertex location (2D/3D Point OCS when 2D, WCS when 3D)

Vertex.dxf.
start_width
¶
line segment start width (float); default=0

Vertex.dxf.
end_width
¶
line segment end width (float); default=0

Vertex.dxf.
bulge
¶
Bulge (float); default=0. The bulge is the tangent of one fourth the included angle for an arc segment, made negative if the arc goes clockwise from the start point to the endpoint. A bulge of 0 indicates a straight segment, and a bulge of 1 is a semicircle.

Vertex.dxf.
flags
¶
Constants defined in ezdxf.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 

Vertex.dxf.
tangent
¶
curve fit tangent direction (float)

Vertex.dxf.
vtx1
¶
index of 1st vertex, if used as face (feature for experts)

Vertex.dxf.
vtx2
¶
index of 2nd vertex, if used as face (feature for experts)

Vertex.dxf.
vtx3
¶
index of 3rd vertex, if used as face (feature for experts)

Vertex.dxf.
vtx4
¶
index of 4th vertex, if used as face (feature for experts)
Polymesh¶

class
Polymesh
(Polyline)¶
A polymesh is a grid of mcount x ncount vertices and every vertex has its own xyzcoordinates.
The Polymesh
is an extended Polyline
class, dxftype is also POLYLINE
but
get_mode()
returns AcDbPolygonMesh
.
Create polymeshes in layouts and blocks by factory function add_polymesh()
.

Polymesh.
get_mesh_vertex
(pos)¶
Get mesh vertex at position pos as Vertex
.
param pos:  0based (row, col)tuple 


Polymesh.
set_mesh_vertex
(pos, point, dxfattribs=None)¶
Set mesh vertex at position pos to location point and update the dxf attributes of the Vertex
.
param pos:  0based (row, col)tuple 

param point:  vertex coordinates as (x, y, z)tuple 
param dxfattribs:  
dict of DXF attributes for the Vertex 

Polymesh.
get_mesh_vertex_cache
()¶
Get a MeshVertexCache
object for this Polymesh. The caching object provides fast access to the location
attributes of the mesh vertices.

class
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]

MeshVertexCache.
vertices
¶
Dict of mesh vertices, keys are 0based (row, col)tuples. Writing to this dict doesn’t change the DXF entity.

MeshVertexCache.
__getitem__
(pos)¶
Returns the location of Vertex
at position pos as (x, y, z)tuple
param tuple pos:  

0based (row, col)tuple 

MeshVertexCache.
__setitem__
(pos, location)¶
Set the location of Vertex
at position pos to location.
param pos:  0based (row, col)tuple 

param location:  (x, y, z)tuple 
Polyface¶

class
Polyface
(Polyline)¶
A polyface consist of multiple location independent 3D areas called faces.
The Polyface
is an extended Polyline
class, dxftype is also POLYLINE
but
get_mode()
returns AcDbPolyFaceMesh
.
Create polyfaces in layouts and blocks by factory function add_polyface()
.

Polyface.
append_face
(face, dxfattribs=None)¶
Append one face, dxfattribs is used for all vertices generated. Appending single faces is very inefficient, if
possible use append_faces()
to add a list of new faces.
param face:  a tuple of 3 or 4 3D points, a 3D point is a (x, y, z)tuple 

param dxfattribs:  
dict of DXF attributes for the Vertex 

Polyface.
append_faces
(faces, dxfattribs=None)¶
Append a list of faces, dxfattribs is used for all vertices generated.
param tuple faces:  

a list of faces, a face is a tuple of 3 or 4 3D points, a 3D point is a (x, y, z)tuple  
param dxfattribs:  
dict of DXF attributes for the Vertex 

Polyface.
faces
()¶
Iterate over all faces, a face is a tuple of Vertex
objects; yields (vtx1, vtx2, vtx3[, vtx4], face_record)tuples

Polyface.
indexed_faces
()¶
Returns a list of all vertices and a generator of Face()
objects as tuple:
vertices, faces = polyface.indexed_faces()

Polyface.
optimize
(precision=6)¶
Rebuilds Polyface
with vertex optimization. Merges vertices with nearly same vertex locations.
Polyfaces created by ezdxf are optimized automatically.
param int precision:  

decimal precision for determining identical vertex locations 
See also

class
Face
¶
Represents a single face of the Polyface
entity.

Face.
vertices
¶
List of all Polyface
vertices (without face_records). (read only attribute)

Face.
face_record
¶
The face forming vertex of type AcDbFaceRecord
, contains the indices to the face building vertices. Indices of
the DXF structure are 1based and a negative index indicates the beginning of an invisible edge.
Face.face_record.dxf.color
determines the color of the face. (read only attribute)

Face.
indices
¶
Indices to the face forming vertices as tuple. This indices are 0base and are used to get vertices from the
list Face.vertices
. (read only attribute)

Face.
__iter__
()¶
Iterate over all face vertices as Vertex
objects.

Face.
__len__
()¶
Returns count of face vertices (without face_record).

Face.
__getitem__
(pos)¶
Returns Vertex
at position pos.
param int pos:  vertex position 0based 


Face.
points
()¶
Iterate over all face vertex locations as (x, y, z)tuples.

Face.
is_edge_visible
(pos)¶
Returns True if edge starting at vertex pos is visible else False.
param int pos:  vertex position 0based 
