Layout Types

A Layout represents and manages DXF entities, there are three different layout objects:

  • Modelspace is the common working space, containing basic drawing entities.

  • Paperspace is the arrangement of objects for printing and plotting, this layout contains basic drawing entities and viewports to the Modelspace.

  • BlockLayout works on an associated Block, Blocks are collections of DXF entities for reusing by block references.

Warning

Do not instantiate layout classes by yourself - always use the provided factory functions!

Entity Ownership

A layout owns all entities residing in their entity space, therefore the dxf.owner attribute of any DXFGraphic entity in this layout is the dxf.handle of the layout, and deleting an entity from a layout is the end of life of this entity, because it is also deleted from the EntityDB. It’s possible to just unlink an entity from a layout to assign the entity to another layout, use the move_to_layout() method to move entities between layouts.

BaseLayout

class ezdxf.layouts.BaseLayout

BaseLayout is the common base class for Layout and BlockLayout.

is_alive

False if layout is deleted.

is_active_paperspace

True if is active layout.

is_any_paperspace

True if is any kind of paperspace layout.

is_modelspace

True if is modelspace layout.

is_any_layout

True if is any kind of modelspace or paperspace layout.

is_block_layout

True if not any kind of modelspace or paperspace layout, just a regular block definition.

units

set drawing units.

Type:

Get/Set layout/block drawing units as enum, see also

Type:

ref

__len__() int

Returns count of entities owned by the layout.

__iter__() Iterator[DXFGraphic]

Returns iterable of all drawing entities in this layout.

__getitem__(index)

Get entity at index.

The underlying data structure for storing entities is organized like a standard Python list, therefore index can be any valid list indexing or slicing term, like a single index layout[-1] to get the last entity, or an index slice layout[:10] to get the first 10 or less entities as list[DXFGraphic].

get_extension_dict() ExtensionDict

Returns the associated extension dictionary, creates a new one if necessary.

delete_entity(entity: DXFGraphic) None

Delete entity from layout entity space and the entity database, this destroys the entity.

delete_all_entities() None

Delete all entities from this layout and from entity database, this destroys all entities in this layout.

Unlink entity from layout but does not delete entity from the entity database, this removes entity just from the layout entity space.

purge()

Remove all destroyed entities from the layout entity space.

query(query: str = '*') EntityQuery

Get all DXF entities matching the Entity Query String.

groupby(dxfattrib: str = '', key: KeyFunc | None = None) dict

Returns a dict of entity lists, where entities are grouped by a dxfattrib or a key function.

Parameters:
  • dxfattrib – grouping by DXF attribute like 'layer'

  • key – key function, which accepts a DXFGraphic entity as argument and returns the grouping key of an entity or None to ignore the entity. Reason for ignoring: a queried DXF attribute is not supported by entity.

move_to_layout(entity: DXFGraphic, layout: BaseLayout) None

Move entity to another layout.

Parameters:
  • entity – DXF entity to move

  • layout – any layout (modelspace, paperspace, block) from same drawing

set_redraw_order(handles: dict | Iterable[tuple[str, str]]) None

If the header variable $SORTENTS Regen flag (bit-code value 16) is set, AutoCAD regenerates entities in ascending handles order.

To change redraw order associate a different sort-handle to entities, this redefines the order in which the entities are regenerated. The handles argument can be a dict of entity_handle and sort_handle as (k, v) pairs, or an iterable of (entity_handle, sort_handle) tuples.

The sort-handle doesn’t have to be unique, some or all entities can share the same sort-handle and a sort-handle can be an existing handle.

The “0” handle can be used, but this sort-handle will be drawn as latest (on top of all other entities) and not as first as expected.

Parameters:

handles – iterable or dict of handle associations; an iterable of 2-tuples (entity_handle, sort_handle) or a dict (k, v) association as (entity_handle, sort_handle)

get_redraw_order() Iterable[tuple[str, str]]

Returns iterable for all existing table entries as (entity_handle, sort_handle) pairs, see also set_redraw_order().

entities_in_redraw_order(reverse=False) Iterable[DXFGraphic]

Yields all entities from layout in ascending redraw order or descending redraw order if reverse is True.

add_entity(entity: DXFGraphic) None

Add an existing DXFGraphic entity to a layout, but be sure to unlink (unlink_entity()) entity from the previous owner layout. Adding entities from a different DXF drawing is not supported.

Warning

This is a low-level tool - use it with caution and make sure you understand what you are doing! If used improperly, the DXF document may be damaged.

add_foreign_entity(entity: DXFGraphic, copy=True) None

Add a foreign DXF entity to a layout, this foreign entity could be from another DXF document or an entity without an assigned DXF document. The intention of this method is to add simple entities from another DXF document or from a DXF iterator, for more complex operations use the importer add-on. Especially objects with BLOCK section (INSERT, DIMENSION, MLEADER) or OBJECTS section dependencies (IMAGE, UNDERLAY) can not be supported by this simple method.

Not all DXF types are supported and every dependency or resource reference from another DXF document will be removed except attribute layer will be preserved but only with default attributes like color 7 and linetype CONTINUOUS because the layer attribute doesn’t need a layer table entry.

If the entity is part of another DXF document, it will be unlinked from this document and its entity database if argument copy is False, else the entity will be copied. Unassigned entities like from DXF iterators will just be added.

Supported DXF types:

  • POINT

  • LINE

  • CIRCLE

  • ARC

  • ELLIPSE

  • LWPOLYLINE

  • SPLINE

  • POLYLINE

  • 3DFACE

  • SOLID

  • TRACE

  • SHAPE

  • MESH

  • ATTRIB

  • ATTDEF

  • TEXT

  • MTEXT

  • HATCH

Parameters:
  • entity – DXF entity to copy or move

  • copy – if True copy entity from other document else unlink from other document

Raises:

CopyNotSupported – copying of entity i not supported

add_point(location: UVec, dxfattribs=None) Point

Add a Point entity at location.

Parameters:
  • location – 2D/3D point in WCS

  • dxfattribs – additional DXF attributes

add_line(start: UVec, end: UVec, dxfattribs=None) Line

Add a Line entity from start to end.

Parameters:
  • start – 2D/3D point in WCS

  • end – 2D/3D point in WCS

  • dxfattribs – additional DXF attributes

add_circle(center: UVec, radius: float, dxfattribs=None) Circle

Add a Circle entity. This is an 2D element, which can be placed in space by using OCS.

Parameters:
  • center – 2D/3D point in WCS

  • radius – circle radius

  • dxfattribs – additional DXF attributes

add_ellipse(center: UVec, major_axis: UVec = (1, 0, 0), ratio: float = 1, start_param: float = 0, end_param: float = math.tau, dxfattribs=None) Ellipse

Add an Ellipse entity, ratio is the ratio of minor axis to major axis, start_param and end_param defines start and end point of the ellipse, a full ellipse goes from 0 to 2π. The ellipse goes from start to end param in counter-clockwise direction.

Parameters:
  • center – center of ellipse as 2D/3D point in WCS

  • major_axis – major axis as vector (x, y, z)

  • ratio – ratio of minor axis to major axis in range +/-[1e-6, 1.0]

  • start_param – start of ellipse curve

  • end_param – end param of ellipse curve

  • dxfattribs – additional DXF attributes

add_arc(center: UVec, radius: float, start_angle: float, end_angle: float, is_counter_clockwise: bool = True, dxfattribs=None) Arc

Add an Arc entity. The arc goes from start_angle to end_angle in counter-clockwise direction by default, set parameter is_counter_clockwise to False for clockwise orientation.

Parameters:
  • center – center of arc as 2D/3D point in WCS

  • radius – arc radius

  • start_angle – start angle in degrees

  • end_angle – end angle in degrees

  • is_counter_clockwiseFalse for clockwise orientation

  • dxfattribs – additional DXF attributes

add_solid(points: Iterable[UVec], dxfattribs=None) Solid

Add a Solid entity, points is an iterable of 3 or 4 points.

Hint

The last two vertices are in reversed order: a square has the vertex order 0-1-3-2

Parameters:
  • points – iterable of 3 or 4 2D/3D points in WCS

  • dxfattribs – additional DXF attributes

add_trace(points: Iterable[UVec], dxfattribs=None) Trace

Add a Trace entity, points is an iterable of 3 or 4 points.

Hint

The last two vertices are in reversed order: a square has the vertex order 0-1-3-2

Parameters:
  • points – iterable of 3 or 4 2D/3D points in WCS

  • dxfattribs – additional DXF attributes

add_3dface(points: Iterable[UVec], dxfattribs=None) Face3d

Add a 3DFace entity, points is an iterable 3 or 4 2D/3D points.

Hint

In contrast to SOLID and TRACE, the last two vertices are in regular order: a square has the vertex order 0-1-2-3

Parameters:
  • points – iterable of 3 or 4 2D/3D points in WCS

  • dxfattribs – additional DXF attributes

add_text(text: str, *, height: float | None = None, rotation: float | None = None, dxfattribs=None) Text

Add a Text entity, see also Textstyle.

Parameters:
  • text – content string

  • height – text height in drawing units

  • rotation – text rotation in degrees

  • dxfattribs – additional DXF attributes

add_blockref(name: str, insert: UVec, dxfattribs=None) Insert

Add an Insert entity.

When inserting a block reference into the modelspace or another block layout with different units, the scaling factor between these units should be applied as scaling attributes (xscale, …) e.g. modelspace in meters and block in centimeters, xscale has to be 0.01.

Parameters:
  • name – block name as str

  • insert – insert location as 2D/3D point in WCS

  • dxfattribs – additional DXF attributes

add_auto_blockref(name: str, insert: UVec, values: dict[str, str], dxfattribs=None) Insert

Add an Insert entity. This method adds for each Attdef entity, defined in the block definition, automatically an Attrib entity to the block reference and set (tag, value) DXF attributes of the ATTRIB entities by the (key, value) pairs (both as strings) of the values dict.

The Attrib entities are placed relative to the insert point, which is equal to the block base point.

This method wraps the INSERT and all the ATTRIB entities into an anonymous block, which produces the best visual results, especially for non-uniform scaled block references, because the transformation and scaling is done by the CAD application. But this makes evaluation of block references with attributes more complicated, if you prefer INSERT and ATTRIB entities without a wrapper block use the add_blockref_with_attribs() method.

Parameters:
  • name – block name

  • insert – insert location as 2D/3D point in WCS

  • valuesAttrib tag values as (tag, value) pairs

  • dxfattribs – additional DXF attributes

add_attdef(tag: str, insert: UVec = (0, 0), text: str = '', *, height: float | None = None, rotation: float | None = None, dxfattribs=None) AttDef

Add an AttDef as stand alone DXF entity.

Set position and alignment by the idiom:

layout.add_attdef("NAME").set_placement(
    (2, 3), align=TextEntityAlignment.MIDDLE_CENTER
)
Parameters:
  • tag – tag name as string

  • insert – insert location as 2D/3D point in WCS

  • text – tag value as string

  • height – text height in drawing units

  • rotation – text rotation in degrees

  • dxfattribs – additional DXF attributes

add_polyline2d(points: Iterable[UVec], format: str | None = None, *, close: bool = False, dxfattribs=None) Polyline

Add a 2D Polyline entity.

Parameters:
  • points – iterable of 2D points in WCS

  • closeTrue for a closed polyline

  • format – user defined point format like add_lwpolyline(), default is None

  • dxfattribs – additional DXF attributes

add_polyline3d(points: Iterable[UVec], *, close: bool = False, dxfattribs=None) Polyline

Add a 3D Polyline entity.

Parameters:
  • points – iterable of 3D points in WCS

  • closeTrue for a closed polyline

  • dxfattribs – additional DXF attributes

add_polymesh(size: tuple[int, int] = (3, 3), dxfattribs=None) Polymesh

Add a Polymesh entity, which is a wrapper class for the POLYLINE entity. A polymesh is a grid of mcount x ncount vertices and every vertex has its own (x, y, z)-coordinates.

Parameters:
  • size – 2-tuple (mcount, ncount)

  • dxfattribs – additional DXF attributes

add_polyface(dxfattribs=None) Polyface

Add a Polyface entity, which is a wrapper class for the POLYLINE entity.

Parameters:

dxfattribs – additional DXF attributes for Polyline entity

add_shape(name: str, insert: UVec = (0, 0), size: float = 1.0, dxfattribs=None) Shape

Add a Shape reference to an external stored shape.

Parameters:
  • name – shape name as string

  • insert – insert location as 2D/3D point in WCS

  • size – size factor

  • dxfattribs – additional DXF attributes

add_lwpolyline(points: Iterable[UVec], format: str = 'xyseb', *, close: bool = False, dxfattribs=None) LWPolyline

Add a 2D polyline as LWPolyline entity. A points are defined as (x, y, [start_width, [end_width, [bulge]]]) tuples, but order can be redefined by the format argument. Set start_width, end_width to 0 to be ignored like (x, y, 0, 0, bulge).

The LWPolyline is defined as a single DXF entity and needs less disk space than a Polyline entity. (requires DXF R2000)

Format codes:

  • x = x-coordinate

  • y = y-coordinate

  • s = start width

  • e = end width

  • b = bulge value

  • v = (x, y [,z]) tuple (z-axis is ignored)

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

  • format – user defined point format, default is “xyseb”

  • closeTrue for a closed polyline

  • dxfattribs – additional DXF attributes

add_mtext(text: str, dxfattribs=None) MText

Add a multiline text entity with automatic text wrapping at boundaries as MText entity. (requires DXF R2000)

Parameters:
  • text – content string

  • dxfattribs – additional DXF attributes

add_mtext_static_columns(content: Iterable[str], width: float, gutter_width: float, height: float, dxfattribs=None) MText

Add a multiline text entity with static columns as MText entity. The content is spread across the columns, the count of content strings determine the count of columns.

This factory method adds automatically a column break "\N" at the end of each column text to force a new column. The height attribute should be big enough to reserve enough space for the tallest column. Too small values produce valid DXF files, but the visual result will not be as expected. The height attribute also defines the total height of the MTEXT entity.

(requires DXF R2000)

Parameters:
  • content – iterable of column content

  • width – column width

  • gutter_width – distance between columns

  • height – max. column height

  • dxfattribs – additional DXF attributes

add_mtext_dynamic_manual_height_columns(content: str, width: float, gutter_width: float, heights: Sequence[float], dxfattribs=None) MText

Add a multiline text entity with dynamic columns as MText entity. The content is spread across the columns automatically by the CAD application. The heights sequence determine the height of the columns, except for the last column, which always takes the remaining content. The height value for the last column is required but can be 0, because the value is ignored. The count of heights also determines the count of columns, and max(heights) defines the total height of the MTEXT entity, which may be wrong if the last column requires more space.

This current implementation works best for DXF R2018, because the content is stored as a continuous text in a single MTEXT entity. For DXF versions prior to R2018 the content should be distributed across multiple MTEXT entities (one entity per column), which is not done by ezdxf, but the result is correct for advanced DXF viewers and CAD application, which do the MTEXT content distribution completely by itself.

(requires DXF R2000)

Parameters:
  • content – column content as a single string

  • width – column width

  • gutter_width – distance between columns

  • heights – column height for each column

  • dxfattribs – additional DXF attributes

add_mtext_dynamic_auto_height_columns(content: str, width: float, gutter_width: float, height: float, count: int, dxfattribs=None) MText

Add a multiline text entity with as many columns as needed for the given common fixed height. The content is spread across the columns automatically by the CAD application. The height argument also defines the total height of the MTEXT entity. To get the correct column count requires an exact MTEXT rendering like AutoCAD, which is not done by ezdxf, therefore passing the expected column count is required to calculate the correct total width.

This current implementation works best for DXF R2018, because the content is stored as a continuous text in a single MTEXT entity. For DXF versions prior to R2018 the content should be distributed across multiple MTEXT entities (one entity per column), which is not done by ezdxf, but the result is correct for advanced DXF viewers and CAD application, which do the MTEXT content distribution completely by itself.

Because of the current limitations the use of this method is not recommend. This situation may improve in future releases, but the exact rendering of the content will also slow down the processing speed dramatically.

(requires DXF R2000)

Parameters:
  • content – column content as a single string

  • width – column width

  • gutter_width – distance between columns

  • height – max. column height

  • count – expected column count

  • dxfattribs – additional DXF attributes

add_ray(start: UVec, unit_vector: UVec, dxfattribs=None) Ray

Add a Ray that begins at start point and continues to infinity (construction line). (requires DXF R2000)

Parameters:
  • start – location 3D point in WCS

  • unit_vector – 3D vector (x, y, z)

  • dxfattribs – additional DXF attributes

add_xline(start: UVec, unit_vector: UVec, dxfattribs=None) XLine

Add an infinity XLine (construction line). (requires DXF R2000)

Parameters:
  • start – location 3D point in WCS

  • unit_vector – 3D vector (x, y, z)

  • dxfattribs – additional DXF attributes

add_mline(vertices: Iterable[UVec] | None = None, *, close: bool = False, dxfattribs=None) MLine

Add a MLine entity

Parameters:
  • vertices – MLINE vertices (in WCS)

  • closeTrue to add a closed MLINE

  • dxfattribs – additional DXF attributes

add_spline(fit_points: Iterable[UVec] | None = None, degree: int = 3, dxfattribs=None) Spline

Add a B-spline (Spline entity) defined by the given fit_points - the control points and knot values are created by the CAD application, therefore it is not predictable how the rendered spline will look like, because for every set of fit points exists an infinite set of B-splines.

If fit_points is None, an “empty” spline will be created, all data has to be set by the user.

The SPLINE entity requires DXF R2000.

AutoCAD creates a spline through fit points by a global curve interpolation and an unknown method to estimate the direction of the start- and end tangent.

Parameters:
  • fit_points – iterable of fit points as (x, y[, z]) in WCS, creates an empty Spline if None

  • degree – degree of B-spline, max. degree supported by AutoCAD is 11

  • dxfattribs – additional DXF attributes

add_cad_spline_control_frame(fit_points: Iterable[UVec], tangents: Iterable[UVec] | None = None, dxfattribs=None) Spline

Add a Spline entity passing through the given fit points. This method creates the same control points as CAD applications.

Parameters:
  • fit_points – iterable of fit points as (x, y[, z]) in WCS

  • tangents – start- and end tangent, default is autodetect

  • dxfattribs – additional DXF attributes

add_spline_control_frame(fit_points: Iterable[UVec], degree: int = 3, method: str = 'chord', dxfattribs=None) Spline

Add a Spline entity passing through the given fit_points, the control points are calculated by a global curve interpolation without start- and end tangent constrains. The new SPLINE entity is defined by control points and not by the fit points, therefore the SPLINE looks always the same, no matter which CAD application renders the SPLINE.

  • “uniform”: creates a uniform t vector, from 0 to 1 evenly spaced, see uniform method

  • “distance”, “chord”: creates a t vector with values proportional to the fit point distances, see chord length method

  • “centripetal”, “sqrt_chord”: creates a t vector with values proportional to the fit point sqrt(distances), see centripetal method

  • “arc”: creates a t vector with values proportional to the arc length between fit points.

Use function add_cad_spline_control_frame() to create SPLINE entities from fit points similar to CAD application including start- and end tangent constraints.

Parameters:
  • fit_points – iterable of fit points as (x, y[, z]) in WCS

  • degree – degree of B-spline, max. degree supported by AutoCAD is 11

  • method – calculation method for parameter vector t

  • dxfattribs – additional DXF attributes

add_open_spline(control_points: Iterable[UVec], degree: int = 3, knots: Iterable[float] | None = None, dxfattribs=None) Spline

Add an open uniform Spline defined by control_points. (requires DXF R2000)

Open uniform B-splines start and end at your first and last control point.

Parameters:
  • control_points – iterable of 3D points in WCS

  • degree – degree of B-spline, max. degree supported by AutoCAD is 11

  • knots – knot values as iterable of floats

  • dxfattribs – additional DXF attributes

add_rational_spline(control_points: Iterable[UVec], weights: Sequence[float], degree: int = 3, knots: Iterable[float] | None = None, dxfattribs=None) Spline

Add an open rational uniform Spline defined by control_points. (requires DXF R2000)

weights has to be an iterable of floats, which defines the influence of the associated control point to the shape of the B-spline, therefore for each control point is one weight value required.

Open rational uniform B-splines start and end at the first and last control point.

Parameters:
  • control_points – iterable of 3D points in WCS

  • weights – weight values as iterable of floats

  • degree – degree of B-spline, max. degree supported by AutoCAD is 11

  • knots – knot values as iterable of floats

  • dxfattribs – additional DXF attributes

add_hatch(color: int = 7, dxfattribs=None) Hatch

Add a Hatch entity. (requires DXF R2000)

Parameters:
  • color – fill color as :ref`ACI`, default is 7 (black/white).

  • dxfattribs – additional DXF attributes

add_helix(radius: float, pitch: float, turns: float, ccw=True, dxfattribs=None) Helix

Add a Helix entity.

The center of the helix is always (0, 0, 0) and the helix axis direction is the +z-axis.

Transform the new HELIX by the transform() method to your needs.

Parameters:
  • radius – helix radius

  • pitch – the height of one complete helix turn

  • turns – count of turns

  • ccw – creates a counter-clockwise turning (right-handed) helix if True

  • dxfattribs – additional DXF attributes

add_mpolygon(color: int = const.BYLAYER, fill_color: int | None = None, dxfattribs=None) MPolygon

Add a MPolygon entity. (requires DXF R2000)

The MPOLYGON entity is not a core DXF entity and is not supported by every CAD application or DXF library.

DXF version R2004+ is required to use a fill color different from BYLAYER. For R2000 the fill color is always BYLAYER, set any ACI value to create a filled MPOLYGON entity.

Parameters:
add_mesh(dxfattribs=None) Mesh

Add a Mesh entity. (requires DXF R2007)

Parameters:

dxfattribs – additional DXF attributes

add_image(image_def: ImageDef, insert: UVec, size_in_units: tuple[float, float], rotation: float = 0.0, dxfattribs=None) Image

Add an Image entity, requires a ImageDef entity, see Tutorial for Image and ImageDef. (requires DXF R2000)

Parameters:
  • image_def – required image definition as ImageDef

  • insert – insertion point as 3D point in WCS

  • size_in_units – size as (x, y) tuple in drawing units

  • rotation – rotation angle around the extrusion axis, default is the z-axis, in degrees

  • dxfattribs – additional DXF attributes

add_wipeout(vertices: Iterable[UVec], dxfattribs=None) Wipeout

Add a ezdxf.entities.Wipeout entity, the masking area is defined by WCS vertices.

This method creates only a 2D entity in the xy-plane of the layout, the z-axis of the input vertices are ignored.

add_underlay(underlay_def: UnderlayDefinition, insert: UVec = (0, 0, 0), scale=(1, 1, 1), rotation: float = 0.0, dxfattribs=None) Underlay

Add an Underlay entity, requires a UnderlayDefinition entity, see Tutorial for Underlay and UnderlayDefinition. (requires DXF R2000)

Parameters:
  • underlay_def – required underlay definition as UnderlayDefinition

  • insert – insertion point as 3D point in WCS

  • scale – underlay scaling factor as (x, y, z) tuple or as single value for uniform scaling for x, y and z

  • rotation – rotation angle around the extrusion axis, default is the z-axis, in degrees

  • dxfattribs – additional DXF attributes

add_linear_dim(base: UVec, p1: UVec, p2: UVec, location: UVec | None = None, text: str = '<>', angle: float = 0, text_rotation: float | None = None, dimstyle: str = 'EZDXF', override: dict | None = None, dxfattribs=None) DimStyleOverride

Add horizontal, vertical and rotated Dimension line. If an UCS is used for dimension line rendering, all point definitions in UCS coordinates, translation into WCS and OCS is done by the rendering function. Extrusion vector is defined by UCS or (0, 0, 1) by default. See also: Tutorial for Linear Dimensions

This method returns a DimStyleOverride object - to create the necessary dimension geometry, you have to call render() manually, this two-step process allows additional processing steps on the Dimension entity between creation and rendering.

Note

Ezdxf does not consider all DIMSTYLE variables, so the rendering results are different from CAD applications.

Parameters:
  • base – location of dimension line, any point on the dimension line or its extension will do (in UCS)

  • p1 – measurement point 1 and start point of extension line 1 (in UCS)

  • p2 – measurement point 2 and start point of extension line 2 (in UCS)

  • location – user defined location for the text midpoint (in UCS)

  • textNone or “<>” the measurement is drawn as text, “ “ (a single space) suppresses the dimension text, everything else text is drawn as dimension text

  • dimstyle – dimension style name (DimStyle table entry), default is “EZDXF”

  • angle – angle from ucs/wcs x-axis to dimension line in degrees

  • text_rotation – rotation angle of the dimension text as absolute angle (x-axis=0, y-axis=90) in degrees

  • overrideDimStyleOverride attributes

  • dxfattribs – additional DXF attributes for the DIMENSION entity

Returns: DimStyleOverride

add_multi_point_linear_dim(base: UVec, points: Iterable[UVec], angle: float = 0, ucs: UCS | None = None, avoid_double_rendering: bool = True, dimstyle: str = 'EZDXF', override: dict | None = None, dxfattribs=None, discard=False) None

Add multiple linear dimensions for iterable points. If an UCS is used for dimension line rendering, all point definitions in UCS coordinates, translation into WCS and OCS is done by the rendering function. Extrusion vector is defined by UCS or (0, 0, 1) by default. See also: Tutorial for Linear Dimensions

This method sets many design decisions by itself, the necessary geometry will be generated automatically, no required nor possible render() call. This method is easy to use, but you get what you get.

Note

Ezdxf does not consider all DIMSTYLE variables, so the rendering results are different from CAD applications.

Parameters:
  • base – location of dimension line, any point on the dimension line or its extension will do (in UCS)

  • points – iterable of measurement points (in UCS)

  • angle – angle from ucs/wcs x-axis to dimension line in degrees (0 = horizontal, 90 = vertical)

  • ucs – user defined coordinate system

  • avoid_double_rendering – suppresses the first extension line and the first arrow if possible for continued dimension entities

  • dimstyle – dimension style name (DimStyle table entry), default is “EZDXF”

  • overrideDimStyleOverride attributes

  • dxfattribs – additional DXF attributes for the DIMENSION entity

  • discard – discard rendering result for friendly CAD applications like BricsCAD to get a native and likely better rendering result. (does not work with AutoCAD)

add_aligned_dim(p1: UVec, p2: UVec, distance: float, text: str = '<>', dimstyle: str = 'EZDXF', override: dict | None = None, dxfattribs=None) DimStyleOverride

Add linear dimension aligned with measurement points p1 and p2. If an UCS is used for dimension line rendering, all point definitions in UCS coordinates, translation into WCS and OCS is done by the rendering function. Extrusion vector is defined by UCS or (0, 0, 1) by default. See also: Tutorial for Linear Dimensions

This method returns a DimStyleOverride object, to create the necessary dimension geometry, you have to call DimStyleOverride.render() manually, this two-step process allows additional processing steps on the Dimension entity between creation and rendering.

Note

Ezdxf does not consider all DIMSTYLE variables, so the rendering results are different from CAD applications.

Parameters:
  • p1 – measurement point 1 and start point of extension line 1 (in UCS)

  • p2 – measurement point 2 and start point of extension line 2 (in UCS)

  • distance – distance of dimension line from measurement points

  • textNone or “<>” the measurement is drawn as text, “ “ (a single space) suppresses the dimension text, everything else text is drawn as dimension text

  • dimstyle – dimension style name (DimStyle table entry), default is “EZDXF”

  • overrideDimStyleOverride attributes

  • dxfattribs – additional DXF attributes for the DIMENSION entity

Returns: DimStyleOverride

add_radius_dim(center: UVec, mpoint: UVec | None = None, radius: float | None = None, angle: float | None = None, *, location: UVec | None = None, text: str = '<>', dimstyle: str = 'EZ_RADIUS', override: dict | None = None, dxfattribs=None) DimStyleOverride

Add a radius Dimension line. The radius dimension line requires a center point and a point mpoint on the circle or as an alternative a radius and a dimension line angle in degrees. See also: Tutorial for Radius Dimensions

If a UCS is used for dimension line rendering, all point definitions in UCS coordinates, translation into WCS and OCS is done by the rendering function. Extrusion vector is defined by UCS or (0, 0, 1) by default.

This method returns a DimStyleOverride object - to create the necessary dimension geometry, you have to call render() manually, this two-step process allows additional processing steps on the Dimension entity between creation and rendering.

Following render types are supported:

  • Default text location outside: text aligned with dimension line; dimension style: “EZ_RADIUS”

  • Default text location outside horizontal: “EZ_RADIUS” + dimtoh=1

  • Default text location inside: text aligned with dimension line; dimension style: “EZ_RADIUS_INSIDE”

  • Default text location inside horizontal: “EZ_RADIUS_INSIDE” + dimtih=1

  • User defined text location: argument location != None, text aligned with dimension line; dimension style: “EZ_RADIUS”

  • User defined text location horizontal: argument location != None, “EZ_RADIUS” + dimtoh=1 for text outside horizontal, “EZ_RADIUS” + dimtih=1 for text inside horizontal

Placing the dimension text at a user defined location, overrides the mpoint and the angle argument, but requires a given radius argument. The location argument does not define the exact text location, instead it defines the dimension line starting at center and the measurement text midpoint projected on this dimension line going through location, if text is aligned to the dimension line. If text is horizontal, location is the kink point of the dimension line from radial to horizontal direction.

Note

Ezdxf does not consider all DIMSTYLE variables, so the rendering results are different from CAD applications.

Parameters:
  • center – center point of the circle (in UCS)

  • mpoint – measurement point on the circle, overrides angle and radius (in UCS)

  • radius – radius in drawing units, requires argument angle

  • angle – specify angle of dimension line in degrees, requires argument radius

  • location – user defined dimension text location, overrides mpoint and angle, but requires radius (in UCS)

  • textNone or “<>” the measurement is drawn as text, “ “ (a single space) suppresses the dimension text, everything else text is drawn as dimension text

  • dimstyle – dimension style name (DimStyle table entry), default is “EZ_RADIUS”

  • overrideDimStyleOverride attributes

  • dxfattribs – additional DXF attributes for the DIMENSION entity

Returns: DimStyleOverride

add_radius_dim_2p(center: UVec, mpoint: UVec, *, text: str = '<>', dimstyle: str = 'EZ_RADIUS', override: dict | None = None, dxfattribs=None) DimStyleOverride

Shortcut method to create a radius dimension by center point, measurement point on the circle and the measurement text at the default location defined by the associated dimstyle, for further information see general method add_radius_dim().

  • dimstyle “EZ_RADIUS”: places the dimension text outside

  • dimstyle “EZ_RADIUS_INSIDE”: places the dimension text inside

Parameters:
  • center – center point of the circle (in UCS)

  • mpoint – measurement point on the circle (in UCS)

  • textNone or “<>” the measurement is drawn as text, “ “ (a single space) suppresses the dimension text, everything else text is drawn as dimension text

  • dimstyle – dimension style name (DimStyle table entry), default is “EZ_RADIUS”

  • overrideDimStyleOverride attributes

  • dxfattribs – additional DXF attributes for the DIMENSION entity

Returns: DimStyleOverride

add_radius_dim_cra(center: UVec, radius: float, angle: float, *, text: str = '<>', dimstyle: str = 'EZ_RADIUS', override: dict | None = None, dxfattribs=None) DimStyleOverride

Shortcut method to create a radius dimension by (c)enter point, (r)adius and (a)ngle, the measurement text is placed at the default location defined by the associated dimstyle, for further information see general method add_radius_dim().

  • dimstyle “EZ_RADIUS”: places the dimension text outside

  • dimstyle “EZ_RADIUS_INSIDE”: places the dimension text inside

Parameters:
  • center – center point of the circle (in UCS)

  • radius – radius in drawing units

  • angle – angle of dimension line in degrees

  • textNone or “<>” the measurement is drawn as text, “ “ (a single space) suppresses the dimension text, everything else text is drawn as dimension text

  • dimstyle – dimension style name (DimStyle table entry), default is “EZ_RADIUS”

  • overrideDimStyleOverride attributes

  • dxfattribs – additional DXF attributes for the DIMENSION entity

Returns: DimStyleOverride

add_diameter_dim(center: UVec, mpoint: UVec | None = None, radius: float | None = None, angle: float | None = None, *, location: UVec | None = None, text: str = '<>', dimstyle: str = 'EZ_RADIUS', override: dict | None = None, dxfattribs=None) DimStyleOverride

Add a diameter Dimension line. The diameter dimension line requires a center point and a point mpoint on the circle or as an alternative a radius and a dimension line angle in degrees.

If an UCS is used for dimension line rendering, all point definitions in UCS coordinates, translation into WCS and OCS is done by the rendering function. Extrusion vector is defined by UCS or (0, 0, 1) by default.

This method returns a DimStyleOverride object - to create the necessary dimension geometry, you have to call render() manually, this two-step process allows additional processing steps on the Dimension entity between creation and rendering.

Note

Ezdxf does not consider all DIMSTYLE variables, so the rendering results are different from CAD applications.

Parameters:
  • center – specifies the center of the circle (in UCS)

  • mpoint – specifies the measurement point on the circle (in UCS)

  • radius – specify radius, requires argument angle, overrides p1 argument

  • angle – specify angle of dimension line in degrees, requires argument radius, overrides p1 argument

  • location – user defined location for the text midpoint (in UCS)

  • textNone or "<>" the measurement is drawn as text, “ “ (a single space) suppresses the dimension text, everything else text is drawn as dimension text

  • dimstyle – dimension style name (DimStyle table entry), default is “EZ_RADIUS”

  • overrideDimStyleOverride attributes

  • dxfattribs – additional DXF attributes for the DIMENSION entity

Returns: DimStyleOverride

add_diameter_dim_2p(p1: UVec, p2: UVec, text: str = '<>', dimstyle: str = 'EZ_RADIUS', override: dict | None = None, dxfattribs=None) DimStyleOverride

Shortcut method to create a diameter dimension by two points on the circle and the measurement text at the default location defined by the associated dimstyle, for further information see general method add_diameter_dim(). Center point of the virtual circle is the midpoint between p1 and p2.

  • dimstyle “EZ_RADIUS”: places the dimension text outside

  • dimstyle “EZ_RADIUS_INSIDE”: places the dimension text inside

Parameters:
  • p1 – first point of the circle (in UCS)

  • p2 – second point on the opposite side of the center point of the circle (in UCS)

  • textNone or “<>” the measurement is drawn as text, “ “ (a single space) suppresses the dimension text, everything else text is drawn as dimension text

  • dimstyle – dimension style name (DimStyle table entry), default is “EZ_RADIUS”

  • overrideDimStyleOverride attributes

  • dxfattribs – additional DXF attributes for the DIMENSION entity

Returns: DimStyleOverride

add_angular_dim_2l(base: UVec, line1: tuple[UVec, UVec], line2: tuple[UVec, UVec], *, location: UVec | None = None, text: str = '<>', text_rotation: float | None = None, dimstyle: str = 'EZ_CURVED', override: dict | None = None, dxfattribs=None) DimStyleOverride

Add angular Dimension from two lines. The measurement is always done from line1 to line2 in counter-clockwise orientation. This does not always match the result in CAD applications!

If an UCS is used for angular dimension rendering, all point definitions in UCS coordinates, translation into WCS and OCS is done by the rendering function. Extrusion vector is defined by UCS or (0, 0, 1) by default.

This method returns a DimStyleOverride object - to create the necessary dimension geometry, you have to call render() manually, this two-step process allows additional processing steps on the Dimension entity between creation and rendering.

Note

Ezdxf does not consider all DIMSTYLE variables, so the rendering results are different from CAD applications.

Parameters:
  • base – location of dimension line, any point on the dimension line or its extension is valid (in UCS)

  • line1 – specifies start leg of the angle (start point, end point) and determines extension line 1 (in UCS)

  • line2 – specifies end leg of the angle (start point, end point) and determines extension line 2 (in UCS)

  • location – user defined location for the text midpoint (in UCS)

  • textNone or “<>” the measurement is drawn as text, “ “ (a single space) suppresses the dimension text, everything else text is drawn as dimension text

  • text_rotation – rotation angle of the dimension text as absolute angle (x-axis=0, y-axis=90) in degrees

  • dimstyle – dimension style name (DimStyle table entry), default is “EZ_CURVED”

  • overrideDimStyleOverride attributes

  • dxfattribs – additional DXF attributes for the DIMENSION entity

Returns: DimStyleOverride

add_angular_dim_3p(base: UVec, center: UVec, p1: UVec, p2: UVec, *, location: UVec | None = None, text: str = '<>', text_rotation: float | None = None, dimstyle: str = 'EZ_CURVED', override: dict | None = None, dxfattribs=None) DimStyleOverride

Add angular Dimension from three points (center, p1, p2). The measurement is always done from p1 to p2 in counter-clockwise orientation. This does not always match the result in CAD applications!

If an UCS is used for angular dimension rendering, all point definitions in UCS coordinates, translation into WCS and OCS is done by the rendering function. Extrusion vector is defined by UCS or (0, 0, 1) by default.

This method returns a DimStyleOverride object - to create the necessary dimension geometry, you have to call render() manually, this two-step process allows additional processing steps on the Dimension entity between creation and rendering.

Note

Ezdxf does not consider all DIMSTYLE variables, so the rendering results are different from CAD applications.

Parameters:
  • base – location of dimension line, any point on the dimension line or its extension is valid (in UCS)

  • center – specifies the vertex of the angle

  • p1 – specifies start leg of the angle (center -> p1) and end-point of extension line 1 (in UCS)

  • p2 – specifies end leg of the angle (center -> p2) and end-point of extension line 2 (in UCS)

  • location – user defined location for the text midpoint (in UCS)

  • textNone or “<>” the measurement is drawn as text, “ “ (a single space) suppresses the dimension text, everything else text is drawn as dimension text

  • text_rotation – rotation angle of the dimension text as absolute angle (x-axis=0, y-axis=90) in degrees

  • dimstyle – dimension style name (DimStyle table entry), default is “EZ_CURVED”

  • overrideDimStyleOverride attributes

  • dxfattribs – additional DXF attributes for the DIMENSION entity

Returns: DimStyleOverride

add_angular_dim_cra(center: UVec, radius: float, start_angle: float, end_angle: float, distance: float, *, location: UVec | None = None, text: str = '<>', text_rotation: float | None = None, dimstyle: str = 'EZ_CURVED', override: dict | None = None, dxfattribs=None) DimStyleOverride

Shortcut method to create an angular dimension by (c)enter point, (r)adius and start- and end (a)ngles, the measurement text is placed at the default location defined by the associated dimstyle. The measurement is always done from start_angle to end_angle in counter-clockwise orientation. This does not always match the result in CAD applications! For further information see the more generic factory method add_angular_dim_3p().

Parameters:
  • center – center point of the angle (in UCS)

  • radius – the distance from center to the start of the extension lines in drawing units

  • start_angle – start angle in degrees (in UCS)

  • end_angle – end angle in degrees (in UCS)

  • distance – distance from start of the extension lines to the dimension line in drawing units

  • location – user defined location for the text midpoint (in UCS)

  • textNone or “<>” the measurement is drawn as text, “ “ (a single space) suppresses the dimension text, everything else text is drawn as dimension text

  • text_rotation – rotation angle of the dimension text as absolute angle (x-axis=0, y-axis=90) in degrees

  • dimstyle – dimension style name (DimStyle table entry), default is “EZ_CURVED”

  • overrideDimStyleOverride attributes

  • dxfattribs – additional DXF attributes for the DIMENSION entity

Returns: DimStyleOverride

add_angular_dim_arc(arc: ConstructionArc, distance: float, *, location: UVec | None = None, text: str = '<>', text_rotation: float | None = None, dimstyle: str = 'EZ_CURVED', override: dict | None = None, dxfattribs=None) DimStyleOverride

Shortcut method to create an angular dimension from a ConstructionArc. This construction tool can be created from ARC entities and the tool itself provides various construction class methods. The measurement text is placed at the default location defined by the associated dimstyle. The measurement is always done from start_angle to end_angle of the arc in counter-clockwise orientation. This does not always match the result in CAD applications! For further information see the more generic factory method add_angular_dim_3p().

Parameters:
  • arcConstructionArc

  • distance – distance from start of the extension lines to the dimension line in drawing units

  • location – user defined location for the text midpoint (in UCS)

  • textNone or “<>” the measurement is drawn as text, “ “ (a single space) suppresses the dimension text, everything else text is drawn as dimension text

  • text_rotation – rotation angle of the dimension text as absolute angle (x-axis=0, y-axis=90) in degrees

  • dimstyle – dimension style name (DimStyle table entry), default is “EZ_CURVED”

  • overrideDimStyleOverride attributes

  • dxfattribs – additional DXF attributes for the DIMENSION entity

Returns: DimStyleOverride

add_arc_dim_3p(base: UVec, center: UVec, p1: UVec, p2: UVec, *, location: UVec | None = None, text: str = '<>', text_rotation: float | None = None, dimstyle: str = 'EZ_CURVED', override: dict | None = None, dxfattribs=None) DimStyleOverride

Add ArcDimension from three points (center, p1, p2). Point p1 defines the radius and the start-angle of the arc, point p2 only defines the end-angle of the arc.

If an UCS is used for arc dimension rendering, all point definitions in UCS coordinates, translation into WCS and OCS is done by the rendering function. Extrusion vector is defined by UCS or (0, 0, 1) by default.

This method returns a DimStyleOverride object - to create the necessary dimension geometry, you have to call render() manually, this two-step process allows additional processing steps on the ArcDimension entity between creation and rendering.

Note

Ezdxf does not render the arc dimension like CAD applications and does not consider all DIMSTYLE variables, so the rendering results are very different from CAD applications.

Parameters:
  • base – location of dimension line, any point on the dimension line or its extension is valid (in UCS)

  • center – specifies the vertex of the angle

  • p1 – specifies the radius (center -> p1) and the star angle of the arc, this is also the start point for the 1st extension line (in UCS)

  • p2 – specifies the end angle of the arc. The start 2nd extension line is defined by this angle and the radius defined by p1 (in UCS)

  • location – user defined location for the text midpoint (in UCS)

  • textNone or “<>” the measurement is drawn as text, “ “ (a single space) suppresses the dimension text, everything else text is drawn as dimension text

  • text_rotation – rotation angle of the dimension text as absolute angle (x-axis=0, y-axis=90) in degrees

  • dimstyle – dimension style name (DimStyle table entry), default is “EZ_CURVED”

  • overrideDimStyleOverride attributes

  • dxfattribs – additional DXF attributes for the DIMENSION entity

Returns: DimStyleOverride

add_arc_dim_cra(center: UVec, radius: float, start_angle: float, end_angle: float, distance: float, *, location: UVec | None = None, text: str = '<>', text_rotation: float | None = None, dimstyle: str = 'EZ_CURVED', override: dict | None = None, dxfattribs=None) DimStyleOverride

Shortcut method to create an arc dimension by (c)enter point, (r)adius and start- and end (a)ngles, the measurement text is placed at the default location defined by the associated dimstyle.

Note

Ezdxf does not render the arc dimension like CAD applications and does not consider all DIMSTYLE variables, so the rendering results are very different from CAD applications.

Parameters:
  • center – center point of the angle (in UCS)

  • radius – the distance from center to the start of the extension lines in drawing units

  • start_angle – start-angle in degrees (in UCS)

  • end_angle – end-angle in degrees (in UCS)

  • distance – distance from start of the extension lines to the dimension line in drawing units

  • location – user defined location for text midpoint (in UCS)

  • textNone or “<>” the measurement is drawn as text, “ “ (a single space) suppresses the dimension text, everything else text is drawn as dimension text

  • text_rotation – rotation angle of the dimension text as absolute angle (x-axis=0, y-axis=90) in degrees

  • dimstyle – dimension style name (DimStyle table entry), default is “EZ_CURVED”

  • overrideDimStyleOverride attributes

  • dxfattribs – additional DXF attributes for the DIMENSION entity

Returns: DimStyleOverride

add_arc_dim_arc(arc: ConstructionArc, distance: float, *, location: UVec | None = None, text: str = '<>', text_rotation: float | None = None, dimstyle: str = 'EZ_CURVED', override: dict | None = None, dxfattribs=None) DimStyleOverride

Shortcut method to create an arc dimension from a ConstructionArc. This construction tool can be created from ARC entities and the tool itself provides various construction class methods. The measurement text is placed at the default location defined by the associated dimstyle.

Note

Ezdxf does not render the arc dimension like CAD applications and does not consider all DIMSTYLE variables, so the rendering results are very different from CAD applications.

Parameters:
  • arcConstructionArc

  • distance – distance from start of the extension lines to the dimension line in drawing units

  • location – user defined location for the text midpoint (in UCS)

  • textNone or “<>” the measurement is drawn as text, “ “ (a single space) suppresses the dimension text, everything else text is drawn as dimension text

  • text_rotation – rotation angle of the dimension text as absolute angle (x-axis=0, y-axis=90) in degrees

  • dimstyle – dimension style name (DimStyle table entry), default is “EZ_CURVED”

  • overrideDimStyleOverride attributes

  • dxfattribs – additional DXF attributes for the DIMENSION entity

Returns: DimStyleOverride

add_ordinate_dim(feature_location: UVec, offset: UVec, dtype: int, *, origin: UVec = NULLVEC, rotation: float = 0.0, text: str = '<>', dimstyle: str = 'EZDXF', override: dict | None = None, dxfattribs=None) DimStyleOverride

Add an ordinate type Dimension line. The feature location is defined in the global coordinate system, which is set as render UCS, which is the WCS by default.

If an UCS is used for dimension line rendering, all point definitions in UCS coordinates, translation into WCS and OCS is done by the rendering function. Extrusion vector is defined by UCS or (0, 0, 1) by default.

This method returns a DimStyleOverride object - to create the necessary dimension geometry, you have to call render() manually, this two-step process allows additional processing steps on the Dimension entity between creation and rendering.

Note

Ezdxf does not consider all DIMSTYLE variables, so the rendering results are different from CAD applications.

Parameters:
  • feature_location – feature location in the global coordinate system (UCS)

  • offset – offset vector of leader end point from the feature location in the local coordinate system

  • dtype – 1 = x-type, 0 = y-type

  • origin – specifies the origin (0, 0) of the local coordinate system in UCS

  • rotation – rotation angle of the local coordinate system in degrees

  • textNone or “<>” the measurement is drawn as text, “ “ (a single space) suppresses the dimension text, everything else text is drawn as dimension text

  • dimstyle – dimension style name (DimStyle table entry), default is “EZDXF”

  • overrideDimStyleOverride attributes

  • dxfattribs – additional DXF attributes for the DIMENSION entity

Returns: DimStyleOverride

add_ordinate_x_dim(feature_location: UVec, offset: UVec, *, origin: UVec = NULLVEC, rotation: float = 0.0, text: str = '<>', dimstyle: str = 'EZDXF', override: dict | None = None, dxfattribs=None) DimStyleOverride

Shortcut to add an x-type feature ordinate DIMENSION, for more information see add_ordinate_dim().

add_ordinate_y_dim(feature_location: UVec, offset: UVec, *, origin: UVec = NULLVEC, rotation: float = 0.0, text: str = '<>', dimstyle: str = 'EZDXF', override: dict | None = None, dxfattribs=None) DimStyleOverride

Shortcut to add a y-type feature ordinate DIMENSION, for more information see add_ordinate_dim().

add_leader(vertices: Iterable[UVec], dimstyle: str = 'EZDXF', override: dict | None = None, dxfattribs=None) Leader

The Leader entity represents an arrow, made up of one or more vertices (or spline fit points) and an arrowhead. The label or other content to which the Leader is attached is stored as a separate entity, and is not part of the Leader itself. (requires DXF R2000)

Leader shares its styling infrastructure with Dimension.

By default a Leader without any annotation is created. For creating more fancy leaders and annotations see documentation provided by Autodesk or Demystifying DXF: LEADER and MULTILEADER implementation notes .

Parameters:
  • vertices – leader vertices (in WCS)

  • dimstyle – dimension style name (DimStyle table entry), default is “EZDXF”

  • override – override DimStyleOverride attributes

  • dxfattribs – additional DXF attributes

add_multileader_mtext(style: str = 'Standard', dxfattribs=None) MultiLeaderMTextBuilder

Add a MultiLeader entity but returns a MultiLeaderMTextBuilder.

add_multileader_block(style: str = 'Standard', dxfattribs=None) MultiLeaderBlockBuilder

Add a MultiLeader entity but returns a MultiLeaderBlockBuilder.

add_body(dxfattribs=None) Body

Add a Body entity. (requires DXF R2000 or later)

The ACIS data has to be set as SAT or SAB.

add_region(dxfattribs=None) Region

Add a Region entity. (requires DXF R2000 or later)

The ACIS data has to be set as SAT or SAB.

add_3dsolid(dxfattribs=None) Solid3d

Add a 3DSOLID entity (Solid3d). (requires DXF R2000 or later)

The ACIS data has to be set as SAT or SAB.

add_surface(dxfattribs=None) Surface

Add a Surface entity. (requires DXF R2007 or later)

The ACIS data has to be set as SAT or SAB.

add_extruded_surface(dxfattribs=None) ExtrudedSurface

Add a ExtrudedSurface entity. (requires DXF R2007 or later)

The ACIS data has to be set as SAT or SAB.

add_lofted_surface(dxfattribs=None) LoftedSurface

Add a LoftedSurface entity. (requires DXF R2007 or later)

The ACIS data has to be set as SAT or SAB.

add_revolved_surface(dxfattribs=None) RevolvedSurface

Add a RevolvedSurface entity. (requires DXF R2007 or later)

The ACIS data has to be set as SAT or SAB.

add_swept_surface(dxfattribs=None) SweptSurface

Add a SweptSurface entity. (requires DXF R2007 or later)

The ACIS data has to be set as SAT or SAB.

Layout

class ezdxf.layouts.Layout

Layout is a subclass of BaseLayout and common base class of Modelspace and Paperspace.

name

Layout name as shown in tabs of CAD applications.

dxf

Returns the DXF name space attribute of the associated DXFLayout object.

This enables direct access to the underlying LAYOUT entity, e.g. Layout.dxf.layout_flags

__contains__(entity: DXFGraphic | str) bool

Returns True if entity is stored in this layout.

Parameters:

entityDXFGraphic object or handle as hex string

reset_extents(extmin=(+1e20, +1e20, +1e20), extmax=(-1e20, -1e20, -1e20)) None

Reset extents to given values or the AutoCAD default values.

“Drawing extents are the bounds of the area occupied by objects.” (Quote Autodesk Knowledge Network)

Parameters:
  • extmin – minimum extents or (+1e20, +1e20, +1e20) as default value

  • extmax – maximum extents or (-1e20, -1e20, -1e20) as default value

reset_limits(limmin=None, limmax=None) None

Reset limits to given values or the AutoCAD default values.

“Sets an invisible rectangular boundary in the drawing area that can limit the grid display and limit clicking or entering point locations.” (Quote Autodesk Knowledge Network)

The Paperspace class has an additional method reset_paper_limits() to deduce the default limits from the paper size settings.

Parameters:
  • limmin – minimum limits or (0, 0) as default

  • limmax – maximum limits or (paper width, paper height) as default value

set_plot_type(value: int = 5) None

0

last screen display

1

drawing extents

2

drawing limits

3

view specific (defined by Layout.dxf.plot_view_name)

4

window specific (defined by Layout.set_plot_window_limits())

5

layout information (default)

Parameters:

value – plot type

Raises:

DXFValueError – for value out of range

set_plot_style(name: str = 'ezdxf.ctb', show: bool = False) None

Set plot style file of type .ctb.

Parameters:
  • name – plot style filename

  • show – show plot style effect in preview? (AutoCAD specific attribute)

set_plot_window(lower_left: tuple[float, float] = (0, 0), upper_right: tuple[float, float] = (0, 0)) None

Set plot window size in (scaled) paper space units.

Parameters:
  • lower_left – lower left corner as 2D point

  • upper_right – upper right corner as 2D point

plot_viewport_borders(state: bool = True) None
show_plot_styles(state: bool = True) None
plot_centered(state: bool = True) None
plot_hidden(state: bool = True) None
use_standard_scale(state: bool = True) None
use_plot_styles(state: bool = True) None
scale_lineweights(state: bool = True) None
print_lineweights(state: bool = True) None
draw_viewports_first(state: bool = True) None
model_type(state: bool = True) None
update_paper(state: bool = True) None
zoom_to_paper_on_update(state: bool = True) None
plot_flags_initializing(state: bool = True) None
prev_plot_init(state: bool = True) None
set_plot_flags(flag, state: bool = True) None

Modelspace

class ezdxf.layouts.Modelspace

Modelspace is a subclass of Layout.

The modelspace contains the “real” world representation of the drawing subjects in real world units.

name

Name of modelspace is fixed as “Model”.

new_geodata(dxfattribs=None) GeoData

Creates a new GeoData entity and replaces existing ones. The GEODATA entity resides in the OBJECTS section and not in the modelspace, it is linked to the modelspace by an ExtensionDict located in BLOCK_RECORD of the modelspace.

The GEODATA entity requires DXF R2010. The DXF reference does not document if other layouts than the modelspace supports geo referencing, so I assume getting/setting geo data may only make sense for the modelspace.

Parameters:

dxfattribs – DXF attributes for GeoData entity

get_geodata() GeoData | None

Returns the GeoData entity associated to the modelspace or None.

Paperspace

class ezdxf.layouts.Paperspace

Paperspace is a subclass of Layout.

Paperspace layouts are used to create different drawing sheets of the modelspace subjects for printing or PDF export.

name

Layout name as shown in tabs of CAD applications.

page_setup(size=(297, 210), margins=(10, 15, 10, 15), units='mm', offset=(0, 0), rotation=0, scale=16, name='ezdxf', device='DWG to PDF.pc3')

Setup plot settings and paper size and reset viewports. All parameters in given units (mm or inch).

Reset paper limits, extents and viewports.

Parameters:
  • size – paper size as (width, height) tuple

  • margins – (top, right, bottom, left) hint: clockwise

  • units – “mm” or “inch”

  • offset – plot origin offset is 2D point

  • rotation – see table Rotation

  • scale – integer in range [0, 32] defines a standard scale type or as tuple(numerator, denominator) e.g. (1, 50) for scale 1:50

  • name – paper name prefix “{name}_({width}_x_{height}_{unit})”

  • device – device .pc3 configuration file or system printer name

int

Rotation

0

no rotation

1

90 degrees counter-clockwise

2

upside-down

3

90 degrees clockwise

viewports() list[Viewport]

Get all VIEWPORT entities defined in this paperspace layout.

main_viewport() Viewport | None

Returns the main viewport of this paper space layout, or None if no main viewport exist.

add_viewport(center: UVec, size: tuple[float, float], view_center_point: UVec, view_height: float, status: int = 2, dxfattribs=None) Viewport

Add a new Viewport entity.

Viewport status:

  • -1 is on, but is fully off-screen, or is one of the viewports that is not active because the $MAXACTVP count is currently being exceeded.

  • 0 is off

  • any value>0 is on and active. The value indicates the order of stacking for the viewports, where 1 is the “active viewport”, 2 is the next, …

reset_viewports() None

Delete all existing viewports, and create a new main viewport.

reset_main_viewport(center: UVec = None, size: UVec = None) Viewport

Reset the main viewport of this paper space layout to the given values, or reset them to the default values, deduced from the paper settings. Creates a new main viewport if none exist.

Ezdxf does not create a main viewport by default, because CAD applications don’t require one.

Parameters:
  • center – center of the viewport in paper space units

  • size – viewport size as (width, height) tuple in paper space units

reset_paper_limits() None

Set paper limits to default values, all values in paperspace units but without plot scale (?).

get_paper_limits() tuple[Vec2, Vec2]

Returns paper limits in plot paper units, relative to the plot origin.

plot origin = lower left corner of printable area + plot origin offset

Returns:

tuple (Vec2(x1, y1), Vec2(x2, y2)), lower left corner is (x1, y1), upper right corner is (x2, y2).

BlockLayout

class ezdxf.layouts.BlockLayout

BlockLayout is a subclass of BaseLayout.

Block layouts are reusable sets of graphical entities, which can be referenced by multiple Insert entities. Each reference can be placed, scaled and rotated individually and can have it’s own set of DXF Attrib entities attached.

property name: str

Get/set the BLOCK name

property block: Block | None

the associated Block entity.

property endblk: EndBlk | None

the associated EndBlk entity.

property dxf

DXF name space of associated BlockRecord table entry.

property can_explode: bool

Set property to True to allow exploding block references of this block.

property scale_uniformly: bool

Set property to True to allow block references of this block only scale uniformly.

property base_point: Vec3

Get/Set the base point of the block.

__contains__(entity) bool

Returns True if block contains entity.

Parameters:

entityDXFGraphic object or handle as hex string

attdefs() Iterable[AttDef]

Returns iterable of all Attdef entities.

has_attdef(tag: str) bool

Returns True if an Attdef for tag exist.

get_attdef(tag: str) AttDef | None

Returns attached Attdef entity by tag name.

get_attdef_text(tag: str, default: str = '') str

Returns text content for Attdef tag as string or returns default if no Attdef for tag exist.

Parameters:
  • tag – name of tag

  • default – default value if tag not exist