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.

get_mode() → str

Returns a string: 'AcDb2dPolyline', 'AcDb3dPolyline', 'AcDbPolygonMesh' or 'AcDbPolyFaceMesh'

m_close() → None

Close Polymesh in m direction (also closes polylines).

n_close() → None

Close Polymesh in n direction.

close()
__len__()
__getitem__()
points()
append_vertex(point: Vertex, dxfattribs: dict = None) → None

Append 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[Vertex], dxfattribs: dict = None) → None

Append multiple Vertex entities at location points.

Parameters
  • points – iterable of (x, y[, z]) tuples

  • dxfattribs – dict of DXF attributes for Vertex class

insert_vertices(pos: int, points: Iterable[Vertex], dxfattribs: dict = None) → None

Insert Vertex entities at location points at insertion position pos` of list Polyline.vertices.

Parameters
  • pos – insertion position of list Polyline.vertices

  • points – list of (x, y[, z]) tuples

  • dxfattribs – dict of DXF attributes for Vertex class

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

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: Vertex, dxfattribs: dict = 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]) → Vertex

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

Parameters

pos – 0-based (row, col) tuple.

__setitem__(pos: Tuple[int, int], location: Vertex) → 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: dict = 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 entity

append_faces(faces: Iterable[FaceType], dxfattribs: dict = 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 Vertex entity

faces() → Iterable[List[Vertex]]

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 with vertex optimization. Merges vertices with nearly same vertex locations. Polyfaces created by ezdxf are optimized automatically.

Parameters

precision – decimal precision for determining identical vertex locations