MultiLeaderBuilder

These are helper classes to build MultiLeader entities in an easy way. The MultiLeader entity supports two kinds of content, for each exist a specialized builder class:

The usual steps of the building process are:

The Tutorial for MultiLeader shows how to use these helper classes in more detail.

class ezdxf.render.MultiLeaderBuilder

Abstract base class to build MultiLeader entities.

property context: MLeaderContext

Returns the context entity MLeaderContext.

property multileader: MultiLeader

Returns the MultiLeader entity.

add_leader_line(side: ConnectionSide, vertices: Iterable[Vec2]) None

Add leader as iterable of vertices in render UCS coordinates (WCS by default).

Note

Vertical (top, bottom) and horizontal attachment sides (left, right) can not be mixed in a single entity - this is a limitation of the MULTILEADER entity.

Parameters:
  • side – connection side where to attach the leader line

  • vertices – leader vertices

build(insert: Vec2, rotation: float = 0.0, ucs: UCS | None = None) None

Compute the required geometry data. The construction plane is the xy-plane of the given render UCS.

Parameters:
  • insert – insert location for the content in render UCS coordinates

  • rotation – content rotation angle around the render UCS z-axis in degrees

  • ucs – the render UCS, default is the WCS

set_arrow_properties(name: str = '', size: float = 0.0)

Set leader arrow properties all leader lines have the same arrow type.

The MULTILEADER entity is able to support multiple arrows, but this seems to be unsupported by CAD applications and is therefore also not supported by the builder classes.

set_connection_properties(landing_gap: float = 0.0, dogleg_length: float = 0.0)

Set the properties how to connect the leader line to the content.

The landing gap is the space between the content and the start of the leader line. The “dogleg” is the first line segment of the leader in the “horizontal” direction of the content.

set_connection_types(left=HorizontalConnection.by_style, right=HorizontalConnection.by_style, top=VerticalConnection.by_style, bottom=VerticalConnection.by_style)

Set the connection type for each connection side.

set_leader_properties(color: int | RGB = colors.BYBLOCK, linetype: str = 'BYBLOCK', lineweight: int = const.LINEWEIGHT_BYBLOCK, leader_type=LeaderType.straight_lines)

Set leader line properties.

Parameters:
  • color – line color as AutoCAD Color Index (ACI) or RGB tuple

  • linetype – as name string, e.g. “BYLAYER”

  • lineweight – as integer value, see: Lineweights

  • leader_type – straight lines of spline type

set_mleader_style(style: MLeaderStyle)

Reset base properties by MLeaderStyle properties. This also resets the content!

set_overall_scaling(scale: float)

Set the overall scaling factor for the whole entity, except for the leader line vertices!

Parameters:

scale – scaling factor > 0.0

MultiLeaderMTextBuilder

Specialization of MultiLeaderBuilder to build MultiLeader with MTEXT content.

class ezdxf.render.MultiLeaderMTextBuilder
set_content(content: str, color: int | RGB | None = None, char_height: float = 0.0, alignment: TextAlignment = TextAlignment.left, style: str = '')

Set MTEXT content.

Parameters:
  • content – MTEXT content as string

  • color – block color as AutoCAD Color Index (ACI) or RGB tuple

  • char_height – initial char height in drawing units

  • alignmentTextAlignment - left, center, right

  • style – name of Textstyle as string

quick_leader(content: str, target: Vec2, segment1: Vec2, segment2: Vec2 | None = None, connection_type: HorizontalConnection | VerticalConnection = HorizontalConnection.middle_of_top_line, ucs: UCS | None = None) None

Creates a quick MTEXT leader. The target point defines where the leader points to. The segment1 is the first segment of the leader line relative to the target point, segment2 is an optional second line segment relative to the first line segment. The connection_type defines the type of connection (horizontal or vertical) and the MTEXT alignment (left, center or right). Horizontal connections are always left or right aligned, vertical connections are always center aligned.

Parameters:
  • content – MTEXT content string

  • target – leader target point as Vec2

  • segment1 – first leader line segment as relative distance to insert

  • segment2 – optional second leader line segment as relative distance to first line segment

  • connection_type – one of HorizontalConnection or VerticalConnection

  • ucs – the rendering UCS, default is the WCS

MultiLeaderBlockBuilder

Specialization of MultiLeaderBuilder to build MultiLeader with BLOCK content.

class ezdxf.render.MultiLeaderBlockBuilder
property block_layout: BlockLayout

Returns the block layout.

property extents: BoundingBox

Returns the bounding box of the block.

set_content(name: str, color: int | RGB = colors.BYBLOCK, scale: float = 1.0, alignment=BlockAlignment.center_extents)

Set BLOCK content.

Parameters:
  • name – the block name as string

  • color – block color as AutoCAD Color Index (ACI) or RGB tuple

  • scale – the block scaling, not to be confused with overall scaling

  • alignment – the block insertion point or the center of extents

set_attribute(tag: str, text: str, width: float = 1.0)

Add BLOCK attributes based on an ATTDEF entity in the block definition. All properties of the new created ATTRIB entity are defined by the template ATTDEF entity including the location.

Parameters:
  • tag – attribute tag name

  • text – attribute content string

  • width – width factor

Enums

class ezdxf.render.LeaderType(value, names=_not_given, *values, module=None, qualname=None, type=None, start=1, boundary=None)

The leader type.

none
straight_lines
splines
class ezdxf.render.ConnectionSide(value, names=_not_given, *values, module=None, qualname=None, type=None, start=1, boundary=None)

The leader connection side.

Vertical (top, bottom) and horizontal attachment sides (left, right) can not be mixed in a single entity - this is a limitation of the MULTILEADER entity.

left
right
top
bottom
class ezdxf.render.HorizontalConnection(value, names=_not_given, *values, module=None, qualname=None, type=None, start=1, boundary=None)

The horizontal leader connection type.

by_style
top_of_top_line
middle_of_top_line
middle_of_text
middle_of_bottom_line
bottom_of_bottom_line
bottom_of_bottom_line_underline
bottom_of_top_line_underline
bottom_of_top_line
bottom_of_top_line_underline_all
class ezdxf.render.VerticalConnection(value, names=_not_given, *values, module=None, qualname=None, type=None, start=1, boundary=None)

The vertical leader connection type.

by_style
center
center_overline
class ezdxf.render.TextAlignment(value, names=_not_given, *values, module=None, qualname=None, type=None, start=1, boundary=None)

The MText alignment type.

left
center
right
class ezdxf.render.BlockAlignment(value, names=_not_given, *values, module=None, qualname=None, type=None, start=1, boundary=None)

The Block alignment type.

center_extents
insertion_point