Layout Types¶
A Layout represents and manages DXF entities, there are three different layout objects:
Modelspaceis the common working space, containing basic drawing entities.Paperspaceis arrangement of objects for printing and plotting, this layout contains basic drawing entities and viewports to theModelspace.BlockLayoutworks on an associatedBlock, Blocks are collections of drawing 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, this means the dxf.owner attribute of
any DXFGraphic 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.
But it is possible to just unlink an entity from a layout, so it can be assigned to another layout, use the
move_to_layout() method to move entities between layouts.
BaseLayout¶
-
class
ezdxf.layouts.BaseLayout¶ BaseLayoutis the common base class forLayoutandBlockLayout.-
is_alive¶ Falseif layout is deleted.
-
is_active_paperspace¶ Trueif is active layout.
-
is_any_paperspace¶ Trueif is any kind of paperspace layout.
-
is_modelspace¶ Trueif is modelspace layout.
-
is_any_layout¶ Trueif is any kind of modelspace or paperspace layout.
-
is_block_layout¶ Trueif 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__() → Iterable[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 slicelayout[:10]to get the first 10 or less entities asList[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(entity: DXFGraphic) → None¶ Unlink entity from layout but does not delete entity from the entity database, this removes entity just from the layout entity space.
-
query(query: str = '*') → EntityQuery¶ Get all DXF entities matching the Entity Query String.
-
groupby(dxfattrib: str = '', key: KeyFunc = None) → dict¶ Returns a
dictof 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
DXFGraphicentity as argument and returns the grouping key of an entity orNoneto 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
-
add_entity(entity: DXFGraphic) → None¶ Add an existing
DXFGraphicentity 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.
-
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
importeradd-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
7and linetypeCONTINUOUSbecause 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
Truecopy entity from other document else unlink from other document
-
add_point(location: Vertex, dxfattribs: dict = None) → Point¶ Add a
Pointentity at location.- Parameters
location – 2D/3D point in WCS
dxfattribs – additional DXF attributes
-
add_line(start: Vertex, end: Vertex, dxfattribs: dict = None) → Line¶ Add a
Lineentity from start to end.
-
add_circle(center: Vertex, radius: float, dxfattribs: dict = None) → Circle¶ Add a
Circleentity. 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: 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
Ellipseentity, 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 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: Vertex, radius: float, start_angle: float, end_angle: float, is_counter_clockwise: bool = True, dxfattribs: dict = None) → Arc¶ Add an
Arcentity. 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 – additional DXF attributes
-
add_solid(points: Iterable[Vertex], dxfattribs: dict = None) → Solid¶ Add a
Solidentity, points is an iterable of 3 or 4 points.- Parameters
points – iterable of 3 or 4 2D/3D points in WCS
dxfattribs – additional DXF attributes for
Solidentity
-
add_trace(points: Iterable[Vertex], dxfattribs: dict = None) → Trace¶ Add a
Traceentity, points is an iterable of 3 or 4 points.- Parameters
points – iterable of 3 or 4 2D/3D points in WCS
dxfattribs – additional DXF attributes for
Traceentity
-
add_3dface(points: Iterable[Vertex], dxfattribs: dict = None) → Face3d¶ Add a
3DFaceentity, points is an iterable 3 or 4 2D/3D points.- Parameters
points – iterable of 3 or 4 2D/3D points in WCS
dxfattribs – additional DXF attributes for
3DFaceentity
-
add_text(text: str, dxfattribs: dict = None) → Text¶ Add a
Textentity, see alsoStyle.- Parameters
text – content string
dxfattribs – additional DXF attributes for
Textentity
-
add_blockref(name: str, insert: Vertex, dxfattribs: dict = None) → Insert¶ Add an
Insertentity.- Parameters
name – block name as str
insert – insert location as 2D/3D point in WCS
dxfattribs – additional DXF attributes for
Insertentity
-
add_auto_blockref(name: str, insert: Vertex, values: Dict[str, str], dxfattribs: dict = None) → Insert¶ Add an
Insertentity. This method adds for eachAttdefentity, defined in the block definition, automatically anAttribentity to the block reference and settag/valueDXF attributes of the ATTRIB entities by thekey/valuepairs (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.
-
add_attrib(tag: str, text: str, insert: Vertex = (0, 0), dxfattribs: dict = None) → Attrib¶ Add an
Attribas 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 – additional DXF attributes for
Attribentity
-
add_attdef(tag: str, insert: Vertex = (0, 0), text: str = '', dxfattribs: dict = None) → AttDef¶ Add an
AttDefas stand alone DXF entity.Set position and alignment by the idiom:
layout.add_attdef('NAME').set_pos((2, 3), align='MIDDLE_CENTER')
- Parameters
tag – tag name as string
insert – insert location as 2D/3D point in WCS
text – tag value as string
dxfattribs – additional DXF attributes
-
add_polyline2d(points: Iterable[Vertex], dxfattribs: dict = None, format: str = None) → Polyline¶ Add a 2D
Polylineentity.- Parameters
points – iterable of 2D points in WCS
dxfattribs – additional DXF attributes
format – user defined point format like
add_lwpolyline(), default isNone
New in version 0.11: user defined point format
-
add_polyline3d(points: Iterable[Vertex], dxfattribs: dict = None) → Polyline¶ Add a 3D
Polylineentity.- Parameters
points – iterable of 3D points in WCS
dxfattribs – additional DXF attributes
-
add_polymesh(size: Tuple[int, int] = (3, 3), dxfattribs: dict = None) → Polymesh¶ Add a
Polymeshentity, 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 for
Polylineentity
-
add_polyface(dxfattribs: dict = None) → Polyface¶ Add a
Polyfaceentity, which is a wrapper class for the POLYLINE entity.- Parameters
dxfattribs – additional DXF attributes for
Polylineentity
-
add_shape(name: str, insert: Vertex = (0, 0), size: float = 1.0, dxfattribs: dict = None) → Shape¶ Add a
Shapereference to a 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[Vertex], format: str = 'xyseb', dxfattribs: dict = None) → LWPolyline¶ Add a 2D polyline as
LWPolylineentity. 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 to0to be ignored like (x, y, 0, 0, bulge).The
LWPolylineis defined as a single DXF entity and needs less disk space than aPolylineentity. (requires DXF R2000)Format codes:
x= x-coordinatey= y-coordinates= start widthe= end widthb= bulge valuev= (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"dxfattribs – additional DXF attributes
-
add_mtext(text: str, dxfattribs: dict = None) → MText¶ Add a multiline text entity with automatic text wrapping at boundaries as
MTextentity. (requires DXF R2000)- Parameters
text – content string
dxfattribs – additional DXF attributes
-
add_ray(start: Vertex, unit_vector: Vertex, dxfattribs: dict = None) → Ray¶ Add a
Raythat 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: 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 – additional DXF attributes
-
add_spline(fit_points: Iterable[Vertex] = None, degree: int = 3, dxfattribs: dict = None) → Spline¶ Add a B-spline (
Splineentity) 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 isNone, 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. See also: Tutorial for Spline.
-
add_spline_control_frame(fit_points: Iterable[Vertex], degree: int = 3, method: str = 'chord', dxfattribs: dict = None) → Spline¶ Add a
Splineentity passing through given fit points by global B-spline interpolation, the new SPLINE entity is defined by a control frame and not by the fit points.“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.
- 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
dxfattribs – additional DXF attributes
-
add_open_spline(control_points: Iterable[Vertex], degree: int = 3, knots: Iterable[float] = None, dxfattribs: dict = None) → Spline¶ Add an open uniform
Splinedefined 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 – additional DXF attributes
-
add_closed_spline(control_points: Iterable[Vertex], degree: int = 3, knots: Iterable[float] = None, dxfattribs: dict = None) → Spline¶ Add a closed uniform
Splinedefined 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 – additional DXF attributes
-
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
Splinedefined 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 – additional DXF attributes
-
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
Splinedefined 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 – additional DXF attributes
-
add_hatch(color: int = 7, dxfattribs: dict = None) → Hatch¶ Add a
Hatchentity. (requires DXF R2007)- Parameters
color – ACI (AutoCAD Color Index), default is
7(black/white).dxfattribs – additional DXF attributes
-
add_mesh(dxfattribs: dict = None) → Mesh¶ Add a
Meshentity. (requires DXF R2007)- Parameters
dxfattribs – additional DXF attributes
-
add_image(image_def: ImageDef, insert: Vertex, size_in_units: Tuple[float, float], rotation: float = 0.0, dxfattribs: dict = None) → Image¶ Add an
Imageentity, requires aImageDefentity, see Tutorial for Image and ImageDef. (requires DXF R2000)
-
add_wipeout(vertices: Iterable[Vertex], dxfattribs: dict = None) → Wipeout¶ Add a
ezdxf.entities.Wipeoutentity, 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: UnderlayDef, insert: Vertex = (0, 0, 0), scale=(1, 1, 1), rotation: float = 0.0, dxfattribs: dict = None) → Underlay¶ Add an
Underlayentity, requires aUnderlayDefentity, see Tutorial for Underlay and UnderlayDefinition. (requires DXF R2000)- Parameters
underlay_def – required underlay definition as
UnderlayDefinsert – 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 zrotation – rotation angle around the extrusion axis, default is the z-axis, in degrees
dxfattribs – additional DXF attributes
-
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) → DimStyleOverride¶ Add horizontal, vertical and rotated
Dimensionline. If anUCSis 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 DimensionsThis method returns a
DimStyleOverrideobject - to create the necessary dimension geometry, you have to callrender()manually, this two step process allows additional processing steps on theDimensionentity between creation and rendering.Note
ezdxf ignores some DIMSTYLE variables, so render results may differ from BricsCAD or AutoCAD.
- 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 –
Noneor"<>"the measurement is drawn as text," "(one space) suppresses the dimension text, everything else text is drawn as dimension textdimstyle – dimension style name (
DimStyletable 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
override –
DimStyleOverrideattributesdxfattribs – additional DXF attributes for
Dimensionentity
Returns:
DimStyleOverride
-
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
UCSis 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 DimensionsThis 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 ignores some DIMSTYLE variables, so render results may differ from BricsCAD or AutoCAD.
- 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'override –
DimStyleOverrideattributesdxfattribs – additional DXF attributes for
Dimensionentitydiscard – 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: Vertex, p2: Vertex, distance: float, text: str = '<>', dimstyle: str = 'EZDXF', override: dict = None, dxfattribs: dict = None) → DimStyleOverride¶ Add linear dimension aligned with measurement points p1 and p2. If an
UCSis 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 DimensionsThis method returns a
DimStyleOverrideobject, to create the necessary dimension geometry, you have to callDimStyleOverride.render()manually, this two step process allows additional processing steps on theDimensionentity between creation and rendering.Note
ezdxf ignores some DIMSTYLE variables, so render results may differ from BricsCAD or AutoCAD.
- 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 (
DimStyletable entry), default is'EZDXF'override –
DimStyleOverrideattributesdxfattribs – DXF attributes for
Dimensionentity
Returns:
DimStyleOverride
-
add_radius_dim(center: Vertex, mpoint: Vertex = None, radius: float = None, angle: float = None, location: Vertex = None, text: str = '<>', dimstyle: str = 'EZ_RADIUS', override: dict = None, dxfattribs: dict = None) → DimStyleOverride¶ Add a radius
Dimensionline. 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 DimensionsIf an
UCSis 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
DimStyleOverrideobject - to create the necessary dimension geometry, you have to callrender()manually, this two step process allows additional processing steps on theDimensionentity 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=1Default text location inside: text aligned with dimension line; dimension style:
'EZ_RADIUS_INSIDE'Default text location inside horizontal:
'EZ_RADIUS_INSIDE'+ dimtih=1User 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 ignores some DIMSTYLE variables, so render results may differ from BricsCAD or AutoCAD.
- 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)
text –
Noneor"<>"the measurement is drawn as text," "(one space) suppresses the dimension text, everything else text is drawn as dimension textdimstyle – dimension style name (
DimStyletable entry), default is'EZ_RADIUS'override –
DimStyleOverrideattributesdxfattribs – additional DXF attributes for
Dimensionentity
Returns:
DimStyleOverride
-
add_radius_dim_2p(center: Vertex, mpoint: Vertex, text: str = '<>', dimstyle: str = 'EZ_RADIUS', override: dict = None, dxfattribs: dict = 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 outsidedimstyle
'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)
text –
Noneor"<>"the measurement is drawn as text," "(one space) suppresses the dimension text, everything else text is drawn as dimension textdimstyle – dimension style name (
DimStyletable entry), default is'EZ_RADIUS'override –
DimStyleOverrideattributesdxfattribs – additional DXF attributes for
Dimensionentity
Returns:
DimStyleOverride
-
add_radius_dim_cra(center: Vertex, radius: float, angle: float, text: str = '<>', dimstyle: str = 'EZ_RADIUS', override: dict = None, dxfattribs: dict = 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 outsidedimstyle
'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
text –
Noneor"<>"the measurement is drawn as text," "(one space) suppresses the dimension text, everything else text is drawn as dimension textdimstyle – dimension style name (
DimStyletable entry), default is'EZ_RADIUS'override –
DimStyleOverrideattributesdxfattribs – additional DXF attributes for
Dimensionentity
Returns:
DimStyleOverride
-
add_diameter_dim(center: Vertex, mpoint: Vertex = None, radius: float = None, angle: float = None, location: Vertex = None, text: str = '<>', dimstyle: str = 'EZ_RADIUS', override: dict = None, dxfattribs: dict = None) → DimStyleOverride¶ Add a diameter
Dimensionline. 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
UCSis 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
DimStyleOverrideobject - to create the necessary dimension geometry, you have to callrender()manually, this two step process allows additional processing steps on theDimensionentity between creation and rendering.Note
ezdxf ignores some DIMSTYLE variables, so render results may differ from BricsCAD or AutoCAD.
- 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 text mid point (in UCS)
text –
Noneor"<>"the measurement is drawn as text," "(one space) suppresses the dimension text, everything else text is drawn as dimension textdimstyle – dimension style name (
DimStyletable entry), default is'EZ_RADIUS'override –
DimStyleOverrideattributesdxfattribs – additional DXF attributes for
Dimensionentity
Returns:
DimStyleOverride(not implemented yet!)
-
add_diameter_dim_2p(p1: Vertex, p2: Vertex, text: str = '<>', dimstyle: str = 'EZ_RADIUS', override: dict = None, dxfattribs: dict = 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 mid point between p1 and p2.dimstyle
'EZ_RADIUS': places the dimension text outsidedimstyle
'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)
text –
Noneor"<>"the measurement is drawn as text," "(one space) suppresses the dimension text, everything else text is drawn as dimension textdimstyle – dimension style name (
DimStyletable entry), default is'EZ_RADIUS'override –
DimStyleOverrideattributesdxfattribs – additional DXF attributes for
Dimensionentity
Returns:
DimStyleOverride
-
add_leader(vertices: Iterable[Vertex], dimstyle: str = 'EZDXF', override: dict = None, dxfattribs: dict = None) → Leader¶ The
Leaderentity represents an arrow, made up of one or more vertices (or spline fit points) and an arrowhead. The label or other content to which theLeaderis attached is stored as a separate entity, and is not part of theLeaderitself. (requires DXF R2000)Leadershares its styling infrastructure withDimension.By default a
Leaderwithout 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 (
DimStyletable entry), default is'EZDXF'override – override
DimStyleOverrideattributesdxfattribs – additional DXF attributes for
Leaderentity
-
add_body(acis_data: str = None, dxfattribs: dict = None) → Body¶ Add a
Bodyentity. (requires DXF R2000)- Parameters
acis_data – ACIS data as iterable of text lines as strings, no interpretation by ezdxf possible
dxfattribs – additional DXF attributes
-
add_region(acis_data: str = None, dxfattribs: dict = None) → Region¶ Add a
Regionentity. (requires DXF R2000)- Parameters
acis_data – ACIS data as iterable of text lines as strings, no interpretation by ezdxf possible
dxfattribs – additional DXF attributes
-
add_3dsolid(acis_data: str = None, dxfattribs: dict = None) → Solid3d¶ Add a 3DSOLID entity (
Solid3d). (requires DXF R2000)- Parameters
acis_data – ACIS data as iterable of text lines as strings, no interpretation by ezdxf possible
dxfattribs – additional DXF attributes
-
add_surface(acis_data: str = None, dxfattribs: dict = None) → Surface¶ Add a
Surfaceentity. (requires DXF R2007)- Parameters
acis_data – ACIS data as iterable of text lines as strings, no interpretation by ezdxf possible
dxfattribs – additional DXF attributes
-
add_extruded_surface(acis_data: str = None, dxfattribs: dict = None) → ExtrudedSurface¶ Add a
ExtrudedSurfaceentity. (requires DXF R2007)- Parameters
acis_data – ACIS data as iterable of text lines as strings, no interpretation by ezdxf possible
dxfattribs – additional DXF attributes
-
add_lofted_surface(acis_data: str = None, dxfattribs: dict = None) → LoftedSurface¶ Add a
LoftedSurfaceentity. (requires DXF R2007)- Parameters
acis_data – ACIS data as iterable of text lines as strings, no interpretation by ezdxf possible
dxfattribs – additional DXF attributes
-
add_revolved_surface(acis_data: str = None, dxfattribs: dict = None) → RevolvedSurface¶ Add a
RevolvedSurfaceentity. (requires DXF R2007)- Parameters
acis_data – ACIS data as iterable of text lines as strings, no interpretation by ezdxf possible
dxfattribs – additional DXF attributes
-
add_swept_surface(acis_data: str = None, dxfattribs: dict = None) → SweptSurface¶ Add a
SweptSurfaceentity. (requires DXF R2007)- Parameters
acis_data – ACIS data as iterable of text lines as strings, no interpretation by ezdxf possible
dxfattribs – additional DXF attributes
-
Layout¶
-
class
ezdxf.layouts.Layout¶ Layoutis a subclass ofBaseLayoutand common base class ofModelspaceandPaperspace.-
dxf¶ Returns the DXF name space attribute of the associated
DXFLayoutobject.This enables direct access to the underlying LAYOUT entity, e.g.
Layout.dxf.layout_flags
-
__contains__(entity: Union[DXFGraphic, str]) → bool¶ Returns
Trueif entity is stored in this layout.- Parameters
entity –
DXFGraphicobject or handle as hex string
-
reset_extends() → None¶ Reset extends.
-
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
-
set_redraw_order(handles: Union[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. handles 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().
-
plot_viewport_borders(state: bool = True) → None¶
-
show_plot_styles(state: bool = True) → None¶
-
plot_centered(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¶ Modelspaceis a subclass ofLayout.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: dict = None) → GeoData¶ Creates a new
GeoDataentity and replaces existing ones. The GEODATA entity resides in the OBJECTS section and not in the modelspace, it is linked to the modelspace by anExtensionDictlocated 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
GeoDataentity
-
Paperspace¶
-
class
ezdxf.layouts.Paperspace¶ Paperspaceis a subclass ofLayout.Paperspace layouts are used to create different drawing sheets of the modelspace subjects for printing or PDF export.
-
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, extends 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
-
rename(name: str) → None¶ Rename layout to name, changes the name displayed in tabs by CAD applications, not the internal BLOCK name.
-
viewports() → List[DXFGraphic]¶ Get all VIEWPORT entities defined in the paperspace layout. Returns a list of
Viewportobjects, sorted by id, the first entity is always the paperspace view with an id of 1.
-
add_viewport(center: Vertex, size: Tuple[float, float], view_center_point: Vertex, view_height: float, dxfattribs: dict = None) → Viewport¶ Add a new
Viewportentity.
-
reset_viewports() → None¶ Delete all existing viewports, and add a new main viewport.
-
reset_paper_limits() → None¶ Set paper limits to default values, all values in paperspace units but without plot scale (?).
-
get_paper_limits() → Tuple[Tuple[float, float], Tuple[float, float]]¶ 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 ((x1, y1), (x2, y2)), lower left corner is (x1, y1), upper right corner is (x2, y2).
-
BlockLayout¶
-
class
ezdxf.layouts.BlockLayout¶ BlockLayoutis a subclass ofBaseLayout.Block layouts are reusable sets of graphical entities, which can be referenced by multiple
Insertentities. Each reference can be placed, scaled and rotated individually and can have it’s own set of DXFAttribentities attached.-
name¶ name of the associated BLOCK and BLOCK_RECORD entities.
-
dxf¶ DXF name space of associated
BlockRecordtable entry.
-
can_explode¶ Set property to
Trueto allow exploding block references of this block.
-
scale_uniformly¶ Set property to
Trueto allow block references of this block only scale uniformly.
-
__contains__(entity: Union[DXFGraphic, str]) → bool¶ Returns
Trueif block contains entity.- Parameters
entity –
DXFGraphicobject or handle as hex string
-
attdefs() → Iterable[AttDef]¶ Returns iterable of all
Attdefentities.
-
has_attdef(tag: str) → bool¶ Returns
Trueif anAttdeffor tag exist.
-
get_attdef(tag: str) → Optional[DXFGraphic]¶ Returns attached
Attdefentity by tag name.
-
get_attdef_text(tag: str, default: str = None) → str¶ Returns text content for
Attdeftag as string or returns default if noAttdeffor tag exist.- Parameters
tag – name of tag
default – default value if tag not exist
-