Blocks Section¶
The BLOCKS section is the home all block definitions (BlockLayout
) of a DXF document.
See also
DXF Internals: BLOCKS Section and Block Management Structures
- class ezdxf.sections.blocks.BlocksSection¶
- __iter__() Iterator[BlockLayout] ¶
Iterable of all
BlockLayout
objects.
- __contains__(name: str) bool ¶
Returns
True
ifBlockLayout
name exist.
- __getitem__(name: str) BlockLayout ¶
Returns
BlockLayout
name, raisesDXFKeyError
if name not exist.
- __delitem__(name: str) None ¶
Deletes
BlockLayout
name and all of its content, raisesDXFKeyError
if name not exist.
- get(name: str, default=None) BlockLayout ¶
Returns
BlockLayout
name, returns default if name not exist.
- new(name: str, base_point: UVec = Vec3(0.0, 0.0, 0.0), dxfattribs: Optional[dict] = None) BlockLayout ¶
Create and add a new
BlockLayout
, name is the BLOCK name, base_point is the insertion point of the BLOCK.
- new_anonymous_block(type_char: str = 'U', base_point: UVec = Vec3(0.0, 0.0, 0.0)) BlockLayout ¶
Create and add a new anonymous
BlockLayout
, type_char is the BLOCK type, base_point is the insertion point of the BLOCK.type_char
Anonymous Block Type
'U'
'*U###'
anonymous BLOCK'E'
'*E###'
anonymous non-uniformly scaled BLOCK'X'
'*X###'
anonymous HATCH graphic'D'
'*D###'
anonymous DIMENSION graphic'A'
'*A###'
anonymous GROUP'T'
'*T###'
anonymous block for ACAD_TABLE content
- rename_block(old_name: str, new_name: str) None ¶
Rename
BlockLayout
old_name to new_name
- delete_block(name: str, safe: bool = True) None ¶
Delete block. If save is
True
, check if block is still referenced.- Parameters
name – block name (case insensitive)
safe – check if block is still referenced or special block without explicit references
- Raises
DXFKeyError – if block not exists
DXFBlockInUseError – if block is still referenced, and save is True
- delete_all_blocks() None ¶
Delete all blocks without references except modelspace- or paperspace layout blocks, special arrow- and anonymous blocks (DIMENSION, ACAD_TABLE).
Warning
There could exist undiscovered references to blocks which are not documented in the DXF reference, hidden in extended data sections or application defined data, which could produce invalid DXF documents if such referenced blocks will be deleted.
Changed in version 0.14: removed unsafe mode