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 if BlockLayout name exist.

__getitem__(name: str) BlockLayout

Returns BlockLayout name, raises DXFKeyError if name not exist.

__delitem__(name: str) None

Deletes BlockLayout name and all of its content, raises DXFKeyError 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.


Anonymous Block Type


'*U###' anonymous BLOCK


'*E###' anonymous non-uniformly scaled BLOCK


'*X###' anonymous HATCH graphic


'*D###' anonymous DIMENSION graphic


'*A###' anonymous GROUP


'*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.

  • name – block name (case insensitive)

  • safe – check if block is still referenced or special block without explicit references

delete_all_blocks() None

Delete all blocks without references except modelspace- or paperspace layout blocks, special arrow- and anonymous blocks (DIMENSION, ACAD_TABLE).


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