LWPolyline

The LWPOLYLINE entity (Lightweight POLYLINE, DXF Reference) is defined as a single graphic entity, which differs from the old-style Polyline entity, which is defined as a group of sub-entities. LWPolyline display faster (in AutoCAD) and consume less disk space, it is a planar element, therefore all points are located in the OCS as (x, y)-tuples (LWPolyline.dxf.elevation is the z-axis value).

Subclass of

ezdxf.entities.DXFGraphic

DXF type

'LWPOLYLINE'

factory function

add_lwpolyline()

Inherited DXF attributes

Common graphical DXF attributes

Required DXF version

DXF R2000 ('AC1015')

Bulge value

The bulge value is used to create arc shaped line segments for Polyline and LWPolyline entities. The arc starts at the vertex which includes the bulge value and ends at the following vertex. The bulge value defines the ratio of the arc sagitta (versine) to half line segment length, a bulge value of 1 defines a semicircle.

The sign of the bulge value defines the side of the bulge:

  • positive value (> 0): bulge is right of line (counter clockwise)

  • negative value (< 0): bulge is left of line (clockwise)

  • 0 = no bulge

../_images/bulge.png

Start- and end width

The start width and end width values defines the width in drawing units for the following line segment. To use the default width value for a line segment set value to 0.

Width and bulge values at last point

The width and bulge values of the last point has only a meaning if the polyline is closed, and they apply to the last line segment from the last to the first point.

User Defined Point Format Codes

Code

Point Component

x

x-coordinate

y

y-coordinate

s

start width

e

end width

b

bulge value

v

(x, y [, z]) as tuple

class ezdxf.entities.LWPolyline
dxf.elevation

OCS z-axis value for all polyline points, default=0

dxf.flags

Constants defined in ezdxf.lldxf.const:

dxf.flags

Value

Description

LWPOLYLINE_CLOSED

1

polyline is closed

LWPOLYLINE_PLINEGEN

128

linetype is generated across the points

dxf.const_width

Constant line width (float), default value is 0.

dxf.count

Count of polyline points (read only), same as len(polyline)

property closed: bool

Get/set closed state of polyline. A closed polyline has a connection segment from the last vertex to the first vertex.

property is_closed: bool

Get closed state of LWPOLYLINE. Compatibility interface to Polyline

close(state: bool = True) None

Set closed state of LWPOLYLINE. Compatibility interface to Polyline

property has_arc: bool

Returns True if LWPOLYLINE has an arc segment.

property has_width: bool

Returns True if LWPOLYLINE has any segment with width attributes or the DXF attribute const_width is not 0.

__len__() int

Returns count of polyline points.

__getitem__(index: int) Tuple[float, float, float, float, float]

Returns point at position index as (x, y, start_width, end_width, bulge) tuple. start_width, end_width and bulge is 0 if not present, supports extended slicing. Point format is fixed as “xyseb”.

All coordinates in OCS.

__setitem__(index: int, value: Sequence[float]) None

Set point at position index as (x, y, [start_width, [end_width, [bulge]]]) tuple. If start_width or end_width is 0 or left off the default width value is used. If the bulge value is left off, bulge is 0 by default (straight line). Does NOT support extend slicing. Point format is fixed as “xyseb”.

All coordinates in OCS.

Parameters:
  • index – point index

  • value – point value as (x, y, [start_width, [end_width, [bulge]]]) tuple

__delitem__(index: int) None

Delete point at position index, supports extended slicing.

__iter__() Iterator[Tuple[float, float, float, float, float]]

Returns iterable of tuples (x, y, start_width, end_width, bulge).

vertices() Iterator[tuple[float, float]]

Returns iterable of all polyline points as (x, y) tuples in OCS (dxf.elevation is the z-axis value).

vertices_in_wcs() Iterator[Vec3]

Returns iterable of all polyline points as Vec3(x, y, z) in WCS.

append(point: Sequence[float], format: str = DEFAULT_FORMAT) None

Append point to polyline, format specifies a user defined point format.

All coordinates in OCS.

Parameters:
  • point – (x, y, [start_width, [end_width, [bulge]]]) tuple

  • format – format string, default is “xyseb”, see: format codes

append_points(points: Iterable[Sequence[float]], format: str = DEFAULT_FORMAT) None

Append new points to polyline, format specifies a user defined point format.

All coordinates in OCS.

Parameters:
  • points – iterable of point, point is (x, y, [start_width, [end_width, [bulge]]]) tuple

  • format – format string, default is “xyseb”, see: format codes

insert(pos: int, point: Sequence[float], format: str = DEFAULT_FORMAT) None

Insert new point in front of positions pos, format specifies a user defined point format.

All coordinates in OCS.

Parameters:
  • pos – insert position

  • point – point data

  • format – format string, default is “xyseb”, see: format codes

clear() None

Remove all points.

get_points(format: str = DEFAULT_FORMAT) list[Sequence[float]]

Returns all points as list of tuples, format specifies a user defined point format.

All points in OCS as (x, y) tuples (dxf.elevation is the z-axis value).

Parameters:

format – format string, default is “xyseb”, see format codes

set_points(points: Iterable[Sequence[float]], format: str = DEFAULT_FORMAT) None

Remove all points and append new points.

All coordinates in OCS.

Parameters:
  • points – iterable of point, point is (x, y, [start_width, [end_width, [bulge]]]) tuple

  • format – format string, default is “xyseb”, see format codes

points(format: str = DEFAULT_FORMAT) Iterator[list[Sequence[float]]]

Context manager for polyline points. Returns a standard Python list of points, according to the format string.

All coordinates in OCS.

Parameters:

format – format string, see format codes

transform(m: Matrix44) LWPolyline

Transform the LWPOLYLINE entity by transformation matrix m inplace.

A non-uniform scaling is not supported if the entity contains circular arc segments (bulges).

Parameters:

m – transformation Matrix44

Raises:

NonUniformScalingError – for non-uniform scaling of entity containing circular arc segments (bulges)

virtual_entities() Iterator[Line | Arc]

Yields the graphical representation of LWPOLYLINE as virtual DXF primitives (LINE or ARC).

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 = None) EntityQuery

Explode the LWPOLYLINE entity as DXF primitives (LINE or ARC) into the target layout, if the target layout is None, the target layout is the layout of the source entity. This method destroys the source entity.

Returns an EntityQuery container referencing all DXF primitives.

Parameters:

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