DXF Graphic Entity Base Class¶
Common base class for all graphical DXF entities.
All graphical entities reside in an entity space like Modelspace
,
any Paperspace
or BlockLayout
.
See also
ezdxf.gfxattribs
module, helper tools to set graphical attributes of DXF entitiesezdxf.colors
module- Tutorial for Common Graphical Attributes
Subclass of | ezdxf.entities.DXFEntity |
Warning
Do not instantiate entity classes by yourself - always use the provided factory functions!
-
class
ezdxf.entities.
DXFGraphic
¶ -
rgb
¶ Get/set DXF attribute
dxf.true_color
as (r, g, b) tuple, returnsNone
if attributedxf.true_color
is not set.entity.rgb = (30, 40, 50) r, g, b = entity.rgb
This is the recommend method to get/set RGB values, when ever possible do not use the DXF low level attribute
dxf.true_color
.
-
transparency
¶ Get/set the transparency value as float. The transparency value is in the range from 0 to 1, where 0 means the entity is opaque and 1 means the entity is 100% transparent (invisible). This is the recommend method to get/set the transparency value, when ever possible do not use the DXF low level attribute
DXFGraphic.dxf.transparency
.This attribute requires DXF R2004 or later, returns 0 for older DXF versions and raises
DXFAttributeError
for setting transparency in older DXF versions.
-
ocs
() → ezdxf.math.ucs.OCS¶ Returns object coordinate system (OCS) for 2D entities like
Text
orCircle
, returns a pass-through OCS for entities without OCS support.
-
get_layout
() → Optional[BaseLayout]¶ Returns the owner layout or returns
None
if entity is not assigned to any layout.
-
unlink_from_layout
() → None¶ Unlink entity from associated layout. Does nothing if entity is already unlinked.
It is more efficient to call the
unlink_entity()
method of the associated layout, especially if you have to unlink more than one entity.
-
copy_to_layout
(layout: BaseLayout) → DXFEntity¶ Copy entity to another layout, returns new created entity as
DXFEntity
object. Copying between different DXF drawings is not supported.Parameters: layout – any layout (model space, paper space, block) Raises: DXFStructureError
– for copying between different DXF drawings
-
move_to_layout
(layout: BaseLayout, source: Optional[BaseLayout] = None) → None¶ Move entity from model space or a paper space layout to another layout. For block layout as source, the block layout has to be specified. Moving between different DXF drawings is not supported.
Parameters: - layout – any layout (model space, paper space, block)
- source – provide source layout, faster for DXF R12, if entity is in a block layout
Raises: DXFStructureError
– for moving between different DXF drawings
-
graphic_properties
() → dict¶ Returns the important common properties layer, color, linetype, lineweight, ltscale, true_color and color_name as dxfattribs dict.
-
has_hyperlink
() → bool¶ Returns
True
if entity has an attached hyperlink.
-
get_hyperlink
() → tuple[str, str, str]¶ Returns hyperlink, description and location.
-
set_hyperlink
(link: str, description: Optional[str] = None, location: Optional[str] = None)¶ Set hyperlink of an entity.
-
transform
(m: ezdxf.math._matrix44.Matrix44) → ezdxf.entities.dxfgfx.DXFGraphic¶ Inplace transformation interface, returns self (floating interface).
Parameters: m – 4x4 transformation matrix ( ezdxf.math.Matrix44
)
-
translate
(dx: float, dy: float, dz: float) → ezdxf.entities.dxfgfx.DXFGraphic¶ Translate entity inplace about dx in x-axis, dy in y-axis and dz in z-axis, returns self (floating interface).
Basic implementation uses the
transform()
interface, subclasses may have faster implementations.
-
scale
(sx: float, sy: float, sz: float) → ezdxf.entities.dxfgfx.DXFGraphic¶ Scale entity inplace about dx in x-axis, dy in y-axis and dz in z-axis, returns self (floating interface).
-
scale_uniform
(s: float) → ezdxf.entities.dxfgfx.DXFGraphic¶ Scale entity inplace uniform about s in x-axis, y-axis and z-axis, returns self (floating interface).
-
rotate_x
(angle: float) → ezdxf.entities.dxfgfx.DXFGraphic¶ Rotate entity inplace about x-axis, returns self (floating interface).
Parameters: angle – rotation angle in radians
-
rotate_y
(angle: float) → ezdxf.entities.dxfgfx.DXFGraphic¶ Rotate entity inplace about y-axis, returns self (floating interface).
Parameters: angle – rotation angle in radians
-
rotate_z
(angle: float) → ezdxf.entities.dxfgfx.DXFGraphic¶ Rotate entity inplace about z-axis, returns self (floating interface).
Parameters: angle – rotation angle in radians
-
rotate_axis
(axis: Union[Sequence[float], ezdxf.math._vector.Vec2, ezdxf.math._vector.Vec3], angle: float) → ezdxf.entities.dxfgfx.DXFGraphic¶ Rotate entity inplace about vector axis, returns self (floating interface).
Parameters: - axis – rotation axis as tuple or
Vec3
- angle – rotation angle in radians
- axis – rotation axis as tuple or
-
Common graphical DXF attributes¶
DXFGraphic.dxf.
layer
¶Layer name as string; default = “0”
DXFGraphic.dxf.
linetype
¶Linetype as string, special names “BYLAYER”, “BYBLOCK”; default value is “BYLAYER”
DXFGraphic.dxf.
color
¶AutoCAD Color Index (ACI), default value is 256
Constants defined in
ezdxf.lldxf.const
or use theezdxf.colors
module
0 BYBLOCK 256 BYLAYER 257 BYOBJECT
DXFGraphic.dxf.
lineweight
¶Line weight in mm times 100 (e.g. 0.13mm = 13). There are fixed valid lineweights which are accepted by AutoCAD, other values prevents AutoCAD from loading the DXF document, BricsCAD isn’t that picky. (requires DXF R2000)
Constants defined in
ezdxf.lldxf.const
-1 LINEWEIGHT_BYLAYER -2 LINEWEIGHT_BYBLOCK -3 LINEWEIGHT_DEFAULT Valid DXF lineweights stored in
VALID_DXF_LINEWEIGHTS
: 0, 5, 9, 13, 15, 18, 20, 25, 30, 35, 40, 50, 53, 60, 70, 80, 90, 100, 106, 120, 140, 158, 200, 211
DXFGraphic.dxf.
ltscale
¶Line type scale as float; default value is 1.0; (requires DXF R2000)
DXFGraphic.dxf.
invisible
¶1 for invisible, 0 for visible; default value is 0; (requires DXF R2000)
DXFGraphic.dxf.
paperspace
¶0 for entity resides in modelspace or a block, 1 for paperspace, this attribute is set automatically by adding an entity to a layout (feature for experts); default value is 0
DXFGraphic.dxf.
extrusion
¶Extrusion direction as 3D vector; default value is (0, 0, 1)
DXFGraphic.dxf.
thickness
¶Entity thickness as float; default value is 0.0; (requires DXF R2000)
DXFGraphic.dxf.
true_color
¶True color value as int 0x00RRGGBB, use
DXFGraphic.rgb
to get/set true color values as (r, g, b) tuples. (requires DXF R2004)
DXFGraphic.dxf.
color_name
¶Color name as string. (requires DXF R2004)
DXFGraphic.dxf.
transparency
¶Transparency value as int, 0x020000TT, 0x00 = 100% transparent / 0xFF = opaque, special value 0x01000000 means transparency by block. An unset transparency value means transparency by layer. Use
DXFGraphic.transparency
to get/set transparency as float value, and the propertiesDXFGraphic.is_transparency_by_block
andDXFGraphic.is_transparency_by_layer
to check special cases.(requires DXF R2004)
DXFGraphic.dxf.
shadow_mode
¶
0 casts and receives shadows 1 casts shadows 2 receives shadows 3 ignores shadows (requires DXF R2007)
See also
ezdxf.gfxattribs
module, helper tools to set graphical attributes of DXF entitiesezdxf.colors
module- Tutorial for Common Graphical Attributes