Blocks Section

The BlocksSection class manages all block definitions of a drawing document.

class BlocksSection
BlocksSection.__iter__()

Iterate over all block definitions, yielding BlockLayout objects.

BlocksSection.__contains__(entity)

Test if BlocksSection contains the block definition entity, entity can be a block name as str or the Block definition itself.

BlocksSection.__getitem__(name)

Get the Block definition by name, raises DXFKeyError if no block name exists.

BlocksSection.get(name, default=None)

Get the Block definition by name, returns default if no block name exists.

BlocksSection.new(name, base_point=(0, 0), dxfattribs=None)

Create and add a new Block, name is the block-name, base_point is the insertion point of the block.

BlocksSection.new_anonymous_block(type_char='U', base_point=(0, 0))

Create and add a new anonymous Block, type_char is the block-type,`base_point` is the insertion point of the block.

BlocksSection.rename_block(old_name, new_name)

Rename block ‘old_name’ in ‘new_name’.

BlockSection.delete_block(name, safe=True)

Delete block name. If safe is True, check if block is still referenced.

Parameters:
  • name – block name (case insensitive)
  • safe – check if block is still referenced
Raises:
  • DXFKeyError – if block name does not exist
  • DXFBlockInUseError – if block name is still referenced, and safe is True
BlockSection.delete_all_blocks(safe=True)

Delete all blocks except layout blocks (model space or paper space).

Parameters:safe – check if block is still referenced before deleting and ignore them if so
type_char Anonymous Block Type
U *U### anonymous blocks
E *E### anonymous non-uniformly scaled blocks
X *X### anonymous hatches
D *D### anonymous dimensions
A *A### anonymous groups
T *T### anonymous block for ACAD_TABLE content