Layout

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

  • Model space is the common working space, containing basic drawing entities.
  • Paper spaces are arrangements of objects for printing and plotting, this layouts contains basic drawing entities and viewports to the model-space.
  • BlockLayout works on an associated Block, Blocks are collections of drawing entities for reusing by block references.

Paper Space Layout Setup

class Layout
Layout.page_setup(size: Tuple[int, int] = (297, 210), margins: Tuple[float, float, float, float] = (10, 15, 10, 15), units: str = 'mm', offset: Tuple[float, float] = (0, 0), rotation: int = 0, scale: int = 16, name: str = 'ezdxf', device: str = 'DWG to PDF.pc3') → None

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

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 – int 0-32 = standard scale type or tuple(numerator, denominator) e.g. (1, 50) for 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
Layout.reset_viewports() → None

Delete all existing viewports, and add a new main viewport. (in page_setup() included)

Layout.reset_extends() → None

Reset paper space extends. (in page_setup() included)

Layout.reset_paper_limits() → None

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

Layout.get_paper_limits() → Tuple[Tuple[float, float], Tuple[float, float]]

Returns paper limits in plot paper units, relative to the plot origin, as tuple ((x1, y1), (x2, y2)). Lower left corner is (x1, y1), upper right corner is (x2, y2).

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

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

Access Existing Entities

Layout.__iter__() → Iterable[DXFGraphic]

Iterate over all drawing entities in this layout.

Returns: DXFGraphic

Layout.__len__() → int

Entities count.

Layout.__contains__(entity: Union[DXFGraphic, str]) → bool
Layout.query(query='*') → ezdxf.query.EntityQuery

Get all DXF entities matching the Entity Query String.

Parameters:query – eintity query string

Returns: EntityQuery

Layout.groupby(dxfattrib: str = '', key: KeyFunc = None) → Dict[Hashable, List[DXFGraphic]]

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 as argument, returns grouping key of this entity or None to ignore this object. Reason for ignoring: a queried DXF attribute is not supported by this entity.

Create New Entities

Layout.add_point(location: Vertex, dxfattribs: dict = None) → Point

Add a Point element at location.

Parameters:
  • location – 2D/3D point in WCS
  • dxfattribs (dist) – additional DXF attributes for Point entity

Returns: Point

Layout.add_line(start: Vertex, end: Vertex, dxfattribs: dict = None) → Line

Add a Line element from start to end.

Parameters:
  • start – 2D/3D point in WCS
  • end – 2D/3D point in WCS
  • dxfattribs (dict) – additional DXF attributes for Line entity

Returns: Line

Layout.add_circle(center: Vertex, radius: float, dxfattribs: dict = None) → Circle

Add a Circle element. 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 (dcit) – additional DXF attributes for Circle entity

Returns: Circle

Layout.add_ellipse(center: Vertex, major_axis: Vertex = (1, 0, 0), ratio: float = 1, start_param: float = 0, end_param: float = 6.283185307179586, dxfattribs: dict = None) → Ellipse

Add an Ellipse element, 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*pi. 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
  • start_param – start of ellipse curve
  • end_param – end param of ellipse curve
  • dxfattribs (dict) – additional DXF attributes for Ellipse entity

Returns: Ellipse

Layout.add_arc(center: Vertex, radius: float, start_angle: float, end_angle: float, is_counter_clockwise: bool = True, dxfattribs: dict = None) → Arc

Add an Arc element. 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_clockwise – False for clockwise orientation
  • dxfattribs (dict) – additional DXF attributes for Arc entity

Returns: Arc

Layout.add_solid(points: Iterable[Vertex], dxfattribs: dict = None) → Solid

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

Parameters:
  • points – iterable of 3 or 4 2D/3D points in WCS
  • dxfattribs (dict) – additional DXF attributes for Solid entity

Returns: Solid

Layout.add_trace(points: Iterable[Vertex], dxfattribs: dict = None) → Trace

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

Parameters:
  • points – iterable of 3 or 4 2D/3D points in WCS
  • dxfattribs (dict) – additional DXF attributes for Trace entity

Returns: Trace

Layout.add_3dface(points: Iterable[Vertex], dxfattribs: dict = None) → Face3d

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

Parameters:
  • points – iterable of 3 or 4 2D/3D points in WCS
  • dxfattribs (dict) – additional DXF attributes for 3DFace entity

Returns: 3DFace

Layout.add_text(text: str, dxfattribs: dict = None) → Text

Add a Text element, see also Style.

Parameters:
  • text – content string
  • dxfattribs (dict) – additional DXF attributes for Text entity

Returns: Text

Layout.add_blockref(name: str, insert: Vertex, dxfattribs: dict = None) → Insert

Add an Insert element.

Parameters:
  • name – block name
  • insert – insert location as 2D/3D point in WCS
  • dxfattribs (dict) – additional DXF attributes for Insert entity

Returns: Insert

Layout.add_auto_blockref(name: str, insert: Vertex, values: Dict[str, str], dxfattribs: dict = None) → Insert

Add an Insert element. 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. The values dict defines the tag/value attributes as key=tag, value=tag value as string. The Attrib entities are placed relative to the insert point, which is equal to the block base point.

Parameters:
  • name – block name
  • insert – insert location as 2D/3D point in WCS
  • values (dict) – Attrib tag values as key=tag, value=tag value pairs
  • dxfattribs (dict) – additional DXF attributes for Insert entity

Returns: Insert

Layout.add_attrib(tag: str, text: str, insert: Vertex = (0, 0), dxfattribs: dict = None) → Attrib

Add an Attrib as stand alone DXF entity.

Parameters:
  • tag – tag name as string
  • text – tag value as string
  • insert – insert location as 2D/3D point in WCS
  • dxfattribs (dict) – additional DXF attributes for Attrib entity

Returns: Attrib

Layout.add_polyline2d(points: Iterable[Vertex], dxfattribs: dict = None) → Polyline

Add a 2D Polyline entity.

Parameters:
  • points – iterable of 2D points in WCS
  • dxfattribs (dict) – additional DXF attributes for Polyline entity

Returns: Polyline

Layout.add_polyline3d(points: Iterable[Vertex], dxfattribs: dict = None) → Polyline

Add a 3D Polyline entity.

Parameters:
  • points – iterable of 3D points in WCS
  • dxfattribs (dict) – additional DXF attributes for Polyline entity

Returns: Polyline

Layout.add_polymesh(size: Tuple[int, int] = (3, 3), dxfattribs: dict = None) → Polymesh

Add a Polymesh entity, which is represented as Polyline entity in the DXF file. A polymesh is a grid of mcount x ncount vertices and every vertex has its own xyz-coordinates.

Parameters:
  • size – 2-tuple (mcount, ncount)
  • dxfattribs (dict) – additional DXF attributes for Polyline entity

Returns: Polymesh

Layout.add_polyface(dxfattribs: dict = None) → Polyface

Add a Polyface entity, which is represented as Polyline entity in the DXF file.

Parameters:dxfattribs (dict) – additional DXF attributes for Polyline entity

Returns: Polyface

Layout.add_shape(name: str, insert: Vertex = (0, 0), size: float = 1.0, dxfattribs: dict = None) → Shape

Add a Shape reference to a external stored shape.

Parameters:
  • name – shape name as string
  • insert – insert location as 2D/3D point in WCS
  • size – size factor
  • dxfattribs (dict) – additional DXF attributes for Shape entity

Returns: Shape

Layout.add_lwpolyline(points: Iterable[Vertex], format: str = 'xyseb', dxfattribs: dict = 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 (x, y, 0, 0, bulge).

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

Parameters:
  • points – iterable of (x, y, [start_width, [end_width, [bulge]]]) tuples
  • format – user defined point format, default is “xyseb”
  • dxfattribs (dict) – additional DXF attributes for LWPolyline entity

Returns: LWPolyline

Layout.add_mtext(text: str, dxfattribs: dict = None) → MText

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

Parameters:
  • text – content string
  • dxfattribs (dict) – additional DXF attributes for MText entity

Returns: MText

Layout.add_ray(start: Vertex, unit_vector: Vertex, dxfattribs: dict = 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 (dict) – additional DXF attributes for Ray entity

Returns: Ray

Layout.add_xline(start: Vertex, unit_vector: Vertex, dxfattribs: dict = 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 (dict) – additional DXF attributes for XLine entity

Returns: XLine

Layout.add_spline(fit_points: Iterable[Vertex] = None, degree: int = 3, dxfattribs: dict = None) → Spline

Add a B-spline defined by 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. (requires DXF R2000+)

AutoCAD creates a spline through fit points by a proprietary algorithm. ezdxf can not reproduce the control point calculation.

Parameters:
  • fit_points – iterable of fit points as (x, y[, z]) in WCS, if None -> user defined spline
  • degree – degree fo B-spline
  • dxfattribs (dict) – additional DXF attributes for Spline entity

Returns: Spline

Layout.add_spline_control_frame(fit_points: Iterable[Vertex], degree: int = 3, method: str = 'distance', power: float = 0.5, dxfattribs: dict = None) → Spline

Create and add B-spline control frame from fit points.

  1. method = “uniform”, creates a uniform t vector, [0…1] equally spaced
  2. method = “distance”, creates a t vector with values proportional to the fit point distances
  3. method = “centripetal”, creates a t vector with values proportional to the fit point distances^power

None of this methods matches the spline created from fit points by AutoCAD.

Parameters:
  • fit_points – iterable of fit points as (x, y[, z]) in WCS
  • degree – degree of B-spline
  • method – calculation method for parameter vector t
  • power – power for centripetal method
  • dxfattribs (dict) – additional DXF attributes for Spline entity

Returns: Spline

Layout.add_spline_approx(fit_points: Iterable[Vertex], count: int, degree: int = 3, method: str = 'distance', power: float = 0.5, dxfattribs: dict = None) → Spline

Approximate B-spline by a reduced count of control points, given are the fit points and the degree of the B-spline.

  1. method = ‘uniform’, creates a uniform t vector, [0…1] equally spaced
  2. method = ‘distance’, creates a t vector with values proportional to the fit point distances
  3. method = ‘centripetal’, creates a t vector with values proportional to the fit point distances^power

(requires DXF R2000+)

Parameters:
  • fit_points – all fit points of B-spline
  • count – count of designated control points
  • degree – degree of B-spline
  • method – calculation method for parameter vector t
  • power – power for centripetal method
  • dxfattribs (dict) – additional DXF attributes for Spline entity

Returns: Spline

Layout.add_open_spline(control_points: Iterable[Vertex], degree: int = 3, knots: Iterable[float] = None, dxfattribs: dict = 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
  • knots – knot values as iterable of floats
  • dxfattribs (dict) – additional DXF attributes for Spline entity

Returns: Spline

Layout.add_closed_spline(control_points: Iterable[Vertex], degree: int = 3, knots: Iterable[float] = None, dxfattribs: dict = None) → Spline

Add a closed uniform Spline defined by control_points. (requires DXF R2000+)

Closed uniform B-splines is a closed curve start and end at the first control point.

Parameters:
  • control_points – iterable of 3D points in WCS
  • degree – degree of B-spline
  • knots – knot values as iterable of floats
  • dxfattribs (dict) – additional DXF attributes for Spline entity

Returns: Spline

Layout.add_rational_spline(control_points: Iterable[Vertex], weights: Sequence[float], degree: int = 3, knots: Iterable[float] = None, dxfattribs: dict = 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
  • knots – knot values as iterable of floats
  • dxfattribs (dict) – additional DXF attributes for Spline entity

Returns: Spline

Layout.add_closed_rational_spline(control_points: Iterable[Vertex], weights: Sequence[float], degree: int = 3, knots: Iterable[float] = None, dxfattribs: dict = None) → Spline

Add a closed 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.

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

Parameters:
  • control_points – iterable of 3D points in WCS
  • weights – weight values as iterable of floats
  • degree – degree of B-spline
  • knots – knot values as iterable of floats
  • dxfattribs (dict) – additional DXF attributes for Spline entity

Returns: Spline

Layout.add_hatch(color: int = 7, dxfattribs: dict = None) → Hatch

Add a Hatch entity. (requires DXF R2007+)

Parameters:
  • color – ACI (AutoCAD Color Index), default is 7 (black/white).
  • dxfattribs (dict) – additional DXF attributes for Hatch entity

Returns: Hatch

Layout.add_mesh(dxfattribs: dict = None) → Mesh

Add a Mesh entity. (requires DXF R2007+)

Parameters:dxfattribs (dict) – additional DXF attributes for Mesh entity

Returns: Mesh

Layout.add_image(image_def: ImageDef, insert: Vertex, size_in_units: Tuple[float, float], rotation: float = 0.0, dxfattribs: dict = None) → Image

Add an Image entity. Create ImageDef by the Drawing factory function add_image_def(), 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 z-axis in degrees
  • dxfattribs (dict) – additional DXF attributes for Image entity

Returns: Image

Layout.add_underlay(underlay_def: UnderlayDef, insert: Vertex = (0, 0, 0), scale=(1, 1, 1), rotation: float = 0.0, dxfattribs: dict = None) → Underlay

Add an Underlay entity. Create UnderlayDef by the Drawing factory function add_underlay_def(), see Tutorial for Underlay and UnderlayDefinition. (requires DXF R2000+)

Parameters:
  • underlay_def – required underlay definition as UnderlayDef
  • 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 z-axis in degrees
  • dxfattribs (dict) – additional DXF attributes for Underlay entity

Returns: Underlay

Layout.add_linear_dim(base: Vertex, p1: Vertex, p2: Vertex, location: Vertex = None, text: str = '<>', angle: float = 0, text_rotation: float = None, dimstyle: str = 'EZDXF', override: dict = None, dxfattribs: dict = None) → ezdxf.dimstyleoverride.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. Manual set extrusion vector will be replaced by OCS defined by UCS or (0, 0, 1) if no UCS is used.

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.

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 text mid point (in UCS)
  • text – None or “<>” the measurement is drawn as text, ” ” (one 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 away from its default orientation (the direction of the dimension line) in degrees
  • overrideDimStyleOverride attributes
  • dxfattribs – DXF attributes for Dimension entity

Returns: DimStyleOverride

Layout.add_multi_point_linear_dim(base: Vertex, points: Iterable[Vertex], angle: float = 0, ucs: UCS = None, avoid_double_rendering: bool = True, dimstyle: str = 'EZDXF', override: dict = None, dxfattribs: dict = 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. Manual set extrusion vector will be replaced by OCS defined by UCS or (0, 0, 1) if no UCS is used.

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.

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 – DXF attributes for 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)
Layout.add_aligned_dim(p1: Vertex, p2: Vertex, distance: float, text: str = '<>', dimstyle: str = 'EZDXF', override: dict = None, dxfattribs: dict = None) → ezdxf.dimstyleoverride.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. Manual set extrusion vector will be replaced by OCS defined by UCS or (0, 0, 1) if no UCS is used.

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.

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
  • text – None or “<>” the measurement is drawn as text, ” ” (one 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 – DXF attributes for Dimension entity

Returns: DimStyleOverride

Layout.add_leader(vertices: Iterable[Vertex], dimstyle: str = 'EZDXF', override: dict = None, dxfattribs: dict = 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.

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 DimStyle attributes
  • dxfattribs – DXF attributes for Leader entity
Layout.add_body(acis_data: str = None, dxfattribs: dict = None) → Body

Add a Body entity. (requires DXF R2000+)

Parameters:
  • acis_data – ACIS data as iterable of text lines as strings, no interpretation by ezdxf possible
  • dxfattribs (dict) – additional DXF attributes for Body entity

Returns: Body

Layout.add_region(acis_data: str = None, dxfattribs: dict = None) → Region

Add a Region entity. (requires DXF R2000+)

Parameters:
  • acis_data – ACIS data as iterable of text lines as strings, no interpretation by ezdxf possible
  • dxfattribs (dict) – additional DXF attributes for Region entity

Returns: Region

Layout.add_3dsolid(acis_data: str = None, dxfattribs: dict = None) → Solid3d

Add a 3DSolid entity. (requires DXF R2000+)

Parameters:
  • acis_data – ACIS data as iterable of text lines as strings, no interpretation by ezdxf possible
  • dxfattribs (dict) – additional DXF attributes for 3DSolid entity

Returns: 3DSolid

Layout.add_surface(acis_data: str = None, dxfattribs: dict = None) → Surface

Add a Surface entity. (requires DXF R2007+)

Parameters:
  • acis_data – ACIS data as iterable of text lines as strings, no interpretation by ezdxf possible
  • dxfattribs (dict) – additional DXF attributes for Surface entity

Returns: Surface

Layout.add_extruded_surface(acis_data: str = None, dxfattribs: dict = None) → ExtrudedSurface

Add a ExtrudedSurface entity. (requires DXF R2007+)

Parameters:
  • acis_data – ACIS data as iterable of text lines as strings, no interpretation by ezdxf possible
  • dxfattribs (dict) – additional DXF attributes for ExtrudedSurface entity

Returns: ExtrudedSurface

Layout.add_lofted_surface(acis_data: str = None, dxfattribs: dict = None) → LoftedSurface

Add a LoftedSurface entity. (requires DXF R2007+)

Parameters:
  • acis_data – ACIS data as iterable of text lines as strings, no interpretation by ezdxf possible
  • dxfattribs (dict) – additional DXF attributes for LoftedSurface entity

Returns: LoftedSurface

Layout.add_revolved_surface(acis_data: str = None, dxfattribs: dict = None) → RevolvedSurface

Add a RevolvedSurface entity. (requires DXF R2007+)

Parameters:
  • acis_data – ACIS data as iterable of text lines as strings, no interpretation by ezdxf possible
  • dxfattribs (dict) – additional DXF attributes for RevolvedSurface entity

Returns: RevolvedSurface

Layout.add_swept_surface(acis_data: str = None, dxfattribs: dict = None) → SweptSurface

Add a SweptSurface entity. (requires DXF R2007+)

Parameters:
  • acis_data – ACIS data as iterable of text lines as strings, no interpretation by ezdxf possible
  • dxfattribs (dict) – additional DXF attributes for SweptSurface entity

Returns: SweptSurface

Change Redraw Order

Layout.set_redraw_order(handles: Union[Dict[KT, VT], 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. handles can be a dict of object_handle and sort_handle as (key, value) pairs, or an iterable of (object_handle, sort_handle) tuples.

The sort_handle doesn’t have to be unique, same or all handles can share the same sort_handle and sort_handles can use existing handles too.

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; for iterable an association is a tuple (object_handle, sort_handle); for dict the association is key: object_handle, value: sort_handle
Layout.get_redraw_order() → Iterable[Tuple[str, str]]

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

Delete Entities

Layout.add_entity(entity: DXFGraphic) → None

Add an existing DXFGraphic to a layout, but be sure to unlink (unlink_entity()) first the entity from the previous owner layout.

Unlink entity from layout but does not delete entity from the drawing database.

Removes entity just from entity space but not from the drawing database.

Parameters:entityDXFGraphic
Layout.delete_entity(entity: DXFGraphic) → None

Delete entity from layout (entity space) and drawing database.

Parameters:entityDXFGraphic

Model Space

At this time the Modelspace class is the Layout class.
Layout.new_geodata(dxfattribs: dict = None) → GeoData

Creates a new GeoData entity and replaces existing ones. The GEODATA entity resides in the OBJECTS section and NOT in the layout entity space and it is linked to the layout by an extension dictionary located in BLOCK_RECORD of the layout.

The GEODATA entity requires DXF version R2010+. The DXF Reference does not document if other layouts than model space supports geo referencing, so getting/setting geo data may only make sense for the model space layout, but it is also available in paper space layouts.

Parameters:dxfattribs (dict) – DXF attributes for the GeoData entity
Layout.get_geodata() → Optional[GeoData]

Returns the GeoData entity associated to this layout or None.

Paper Space

At this time the Paperspace class is the Layout class.

BlockLayout

class BlockLayout(Layout)
BlockLayout.name

The name of the associated block element. (read/write)

BlockLayout.block

Get the associated DXF BLOCK entity.

BlockLayout.is_layout_block

True if block is a model space or paper space block definition.

BlockLayout.add_attdef(tag: str, insert: Sequence[float] = (0, 0), text: str = '', dxfattribs: dict = None) → DXFGraphic

Add an Attdef entity.

Set position and alignment by the idiom:

myblock.add_attdef('NAME').set_pos((2, 3), align='MIDDLE_CENTER')
Parameters:
  • tag – attribute name (tag) as string without spaces
  • insert – attribute insert point relative to block origin (0, 0, 0)
  • text – preset text for attribute
  • dxfattribs – DXF attributes for the new ATTDEF entity
BlockLayout.attdefs() → Iterable[AttDef]

Iterate for all Attdef entities.

BlockLayout.has_attdef(tag: str) → bool

Returns True if an Attdef for tag exists else False.

Parameters:tag – tag name
BlockLayout.get_attdef(tag: str) → Optional[DXFGraphic]

Get attached Attdef entity by tag.

Parameters:tag – tag name

Returns: Attdef

BlockLayout.get_attdef_text(tag: str, default: str = None) → str

Get content text for Attdef tag as string or returns default if no Attdef for tag exists.

Parameters:
  • tag – tag name
  • default – default value if tag is absent