Dictionary

The DICTIONARY is a general storage entity.

AutoCAD maintains items such as MLINE_STYLES and GROUP definitions as objects in dictionaries. Other applications are free to create and use their own dictionaries as they see fit. The prefix 'ACAD_' is reserved for use by AutoCAD applications.

Dictionary entries are (key, DXFEntity) pairs. At loading time the value could be a str, because at this time not all objects are already stored in the EntityDB, and have to be acquired later.

Subclass of

ezdxf.entities.DXFObject

DXF type

'DICTIONARY'

Factory function

ezdxf.sections.objects.ObjectsSection.add_dictionary()

Warning

Do not instantiate object classes by yourself - always use the provided factory functions!

class ezdxf.entities.Dictionary
dxf.hard_owned

If set to 1, indicates that elements of the dictionary are to be treated as hard-owned.

dxf cloning

Duplicate record cloning flag (determines how to merge duplicate entries, ignored by ezdxf):

0

not applicable

1

keep existing

2

use clone

3

<xref>$0$<name>

4

$0$<name>

5

Unmangle name

is_hard_owner

Returns True if Dictionary is hard owner of entities. Hard owned entities will be destroyed by deleting the dictionary.

__len__() → int

Returns count of items.

__contains__(key: str) → bool

Returns True if key exist.

__getitem__(key: str) → DXFEntity

Return the value for key, raises a DXFKeyError if key does not exist.

__setitem__(key: str, value: DXFEntity) → None

Add item as (key, value) pair to dictionary.

__delitem__(key: str) → None

Delete entry key from the dictionary, raises DXFKeyError if key does not exist.

keys() → KeysView

Returns KeysView of all dictionary keys.

items() → ItemsView

Returns ItemsView for all dictionary entries as (key, DXFEntity) pairs.

count() → int

Returns count of items.

get(key: str, default: Any = DXFKeyError) → DXFEntity

Returns DXFEntity for key, if key exist, else default or raises a DXFKeyError for default = DXFKeyError.

add(key: str, value: DXFEntity) → None

Add entry (key, value).

remove(key: str) → None

Delete entry key. Raises DXFKeyError, if key does not exist. Deletes also hard owned DXF objects from OBJECTS section.

discard(key: str) → None

Delete entry key if exists. Does NOT raise an exception if key not exist and does not delete hard owned DXF objects.

clear() → None

Delete all entries from Dictionary, deletes hard owned DXF objects from OBJECTS section.

add_new_dict(key: str, hard_owned: bool = False) → Dictionary

Create a new sub Dictionary.

Parameters
  • key – name of the sub dictionary

  • hard_owned – entries of the new dictionary are hard owned

get_required_dict(key: str) → Dictionary

Get entry key or create a new Dictionary, if Key not exist.

add_dict_var(key: str, value: str) → DictionaryVar

Add new DictionaryVar.

Parameters
  • key – entry name as string

  • value – entry value as string

DictionaryWithDefault

Subclass of

ezdxf.entities.Dictionary

DXF type

'ACDBDICTIONARYWDFLT'

Factory function

ezdxf.sections.objects.ObjectsSection.add_dictionary_with_default()

class ezdxf.entities.DictionaryWithDefault
dxf.default

Handle to default entry as hex string like FF00.

get(key: str) → DXFEntity

Returns DXFEntity for key or the predefined dictionary wide dxf.default entity if key does not exist.

set_default(default: ezdxf.entities.dxfentity.DXFEntity) → None

Set dictionary wide default entry.

Parameters

default – default entry as DXFEntity

DictionaryVar

Subclass of

ezdxf.entities.DXFObject

DXF type

'DICTIONARYVAR'

Factory function

ezdxf.entities.Dictionary.add_dict_var()

dxf.schema

Object schema number (currently set to 0)

dxf.value

Value as string.