Tags

A list of DXFTag, inherits from Python standard list. Unlike the statement in the DXF Reference “Do not write programs that rely on the order given here”, tag order is sometimes essential and some group codes may appear multiples times in one entity. At the worst case (Material: normal map shares group codes with diffuse map) using same group codes with different meanings.

class ezdxf.lldxf.tags.Tags

Subclass of list.

Collection of DXFTag as flat list. Low level tag container, only required for advanced stuff.

classmethod from_text(text: str) Tags

Constructor from DXF string.

dxftype() str

Returns DXF type of entity, e.g. 'LINE'.

get_handle() str

Get DXF handle. Raises DXFValueError if handle not exist.

Returns

handle as plain hex string like 'FF00'

Raises

DXFValueError – no handle found

replace_handle(new_handle: str) None

Replace existing handle.

Parameters

new_handle – new handle as plain hex string e.g. 'FF00'

has_tag(code: int) bool

Returns True if a DXFTag with given group code is present.

Parameters

code – group code as int

has_embedded_objects() bool
get_first_tag(code: int, default=DXFValueError) DXFTag

Returns first DXFTag with given group code or default, if default != DXFValueError, else raises DXFValueError.

Parameters
  • code – group code as int

  • default – return value for default case or raises DXFValueError

get_first_value(code: int, default=DXFValueError) Any

Returns value of first DXFTag with given group code or default if default != DXFValueError, else raises DXFValueError.

Parameters
  • code – group code as int

  • default – return value for default case or raises DXFValueError

find_all(code: int) List[DXFTag]

Returns a list of DXFTag with given group code.

Parameters

code – group code as int

filter(codes: Iterable[int]) Iterable[DXFTag]

Iterate and filter tags by group codes.

Parameters

codes – group codes to filter

collect_consecutive_tags(codes: Iterable[int], start: int = 0, end: int = None) Tags

Collect all consecutive tags with group code in codes, start and end delimits the search range. A tag code not in codes ends the process.

Parameters
  • codes – iterable of group codes

  • start – start index as int

  • end – end index as int, None for end index = len(self)

Returns

collected tags as Tags

tag_index(code: int, start: int = 0, end: Optional[int] = None) int

Return index of first DXFTag with given group code.

Parameters
  • code – group code as int

  • start – start index as int

  • end – end index as int, None for end index = len(self)

update(tag: DXFTag)

Update first existing tag with same group code as tag, raises DXFValueError if tag not exist.

set_first(tag: DXFTag)

Update first existing tag with group code tag.code or append tag.

remove_tags(codes: Iterable[int]) None

Remove all tags inplace with group codes specified in codes.

Parameters

codes – iterable of group codes as int

remove_tags_except(codes: Iterable[int]) None

Remove all tags inplace except those with group codes specified in codes.

Parameters

codes – iterable of group codes

pop_tags(codes: Iterable[int]) Iterable[DXFTag]

Pop tags with group codes specified in codes.

Parameters

codes – iterable of group codes

classmethod strip(tags: Tags, codes: Iterable[int]) Tags

Constructor from tags, strips all tags with group codes in codes from tags.

Parameters
  • tags – iterable of DXFTag

  • codes – iterable of group codes as int

ezdxf.lldxf.tags.group_tags(tags: Iterable[DXFTag], splitcode: int = 0) Iterable[Tags]

Group of tags starts with a SplitTag and ends before the next SplitTag. A SplitTag is a tag with code == splitcode, like (0, ‘SECTION’) for splitcode == 0.

Parameters
  • tags – iterable of DXFTag

  • splitcode – group code of split tag

class ezdxf.lldxf.extendedtags.ExtendedTags(tags: Iterable[DXFTag] = None, legacy=False)

Represents the extended DXF tag structure introduced with DXF R13.

Args:

tags: iterable of DXFTag legacy: flag for DXF R12 tags

appdata

Application defined data as list of Tags

subclasses

Subclasses as list of Tags

xdata

XDATA as list of Tags

embedded_objects

embedded objects as list of Tags

noclass

Short cut to access first subclass.

get_handle() str

Returns handle as hex string.

dxftype() str

Returns DXF type as string like “LINE”.

replace_handle(handle: str) None

Replace the existing entity handle by a new value.

legacy_repair()

Legacy (DXF R12) tags handling and repair.

clone() ExtendedTags

Shallow copy.

flatten_subclasses()

Flatten subclasses in legacy mode (DXF R12).

There exists DXF R12 with subclass markers, technical incorrect but works if the reader ignore subclass marker tags, unfortunately ezdxf tries to use this subclass markers and therefore R12 parsing by ezdxf does not work without removing these subclass markers.

This method removes all subclass markers and flattens all subclasses into ExtendedTags.noclass.

get_subclass(name: str, pos: int = 0) Tags

Get subclass name.

Parameters
  • name – subclass name as string like “AcDbEntity”

  • pos – start searching at subclass pos.

has_xdata(appid: str) bool

True if has XDATA for appid.

get_xdata(appid: str) Tags

Returns XDATA for appid as Tags.

set_xdata(appid: str, tags: IterableTags) None

Set tags as XDATA for appid.

new_xdata(appid: str, tags: 'IterableTags' = None) Tags

Append a new XDATA block.

Assumes that no XDATA block with the same appid already exist:

try:
    xdata = tags.get_xdata('EZDXF')
except ValueError:
    xdata = tags.new_xdata('EZDXF')
has_app_data(appid: str) bool

True if has application defined data for appid.

get_app_data(appid: str) Tags

Returns application defined data for appid as Tags including marker tags.

get_app_data_content(appid: str) Tags

Returns application defined data for appid as Tags without first and last marker tag.

set_app_data_content(appid: str, tags: IterableTags) None

Set application defined data for appid for already exiting data.

new_app_data(appid: str, tags: 'IterableTags' = None, subclass_name: str = None) Tags

Append a new application defined data to subclass subclass_name.

Assumes that no app data block with the same appid already exist:

try:
    app_data = tags.get_app_data('{ACAD_REACTORS', tags)
except ValueError:
    app_data = tags.new_app_data('{ACAD_REACTORS', tags)
classmethod from_text(text: str, legacy: bool = False) ExtendedTags

Create ExtendedTags from DXF text.

Packed DXF Tags

Store DXF tags in compact data structures as list or array.array to reduce memory usage.

class ezdxf.lldxf.packedtags.TagList(data: Iterable = None)

Store data in a standard Python list.

Args:

data: iterable of DXF tag values.

values

Data storage as list.

clone() TagList

Returns a deep copy.

classmethod from_tags(tags: Tags, code: int) TagList

Setup list from iterable tags.

Parameters
  • tags – tag collection as Tags

  • code – group code to collect

clear() None

Delete all data values.

class ezdxf.lldxf.packedtags.TagArray(data: Iterable = None)

TagArray is a subclass of TagList, which store data in an array.array. Array type is defined by class variable DTYPE.

Args:

data: iterable of DXF tag values.

DTYPE

array.array type as string

values

Data storage as array.array

set_values(values: Iterable) None

Replace data by values.

class ezdxf.lldxf.packedtags.VertexArray(data: Iterable = None)

Store vertices in an array.array('d'). Vertex size is defined by class variable VERTEX_SIZE.

Args:

data: iterable of vertex values as linear list e.g. [x1, y1, x2, y2, x3, y3, ...].

VERTEX_SIZE

Size of vertex (2 or 3 axis).

__len__() int

Count of vertices.

__getitem__(index: int)

Get vertex at index, extended slicing supported.

__setitem__(index: int, point: Sequence[float]) None

Set vertex point at index, extended slicing not supported.

__delitem__(index: int) None

Delete vertex at index, extended slicing supported.

__iter__() Iterator[Sequence[float]]

Returns iterable of vertices.

__str__() str

String representation.

insert(pos: int, point: Sequence[float])

Insert point in front of vertex at index pos.

Parameters
  • pos – insert position

  • point – point as tuple

append(point: Sequence[float]) None

Append point.

extend(points: Iterable[Sequence[float]]) None

Extend array by points.

set(points: Iterable[Sequence[float]]) None

Replace all vertices by points.

clear() None

Delete all vertices.

clone() VertexArray

Returns a deep copy.

classmethod from_tags(tags: Iterable[DXFTag], code: int = 10) VertexArray

Setup point array from iterable tags.

Parameters
  • tags – iterable of DXFVertex

  • code – group code to collect

export_dxf(tagwriter: ezdxf.lldxf.tagwriter.TagWriter, code=10)