Tag Data Structures

Required DXF tag interface:

  • property code: group code as int
  • property value: tag value of unspecific type
  • method dxfstr(): returns the DXF string
  • method clone(): returns a deep copy of tag

DXFTag

The DXFTag is the basic DXF data type, this data type is per definition immutable (but not per implementation for sake of speed)
class ezdxf.lldxf.DXFTag
DXFTag.code

DXF group code (read only), interface definition

DXFTag.value

DXF tag value (read only)

DXFTag.__str__()
DXFTag.__repr__()
DXFTag.__getitem__()

Support for indexing.

DXFTag.__iter__()

Support for iterator protocol.

DXFTag.dxfstr()

Returns the DXF string e.g. ‘ 0nLINEn’

DXFTag.clone()

Returns a clone of itself, this method is necessary for the more complex (and not immutable) DXF tag types.

DXFBinaryTag

Represents binary data compact as binary strings. This tag is immutable.
class ezdxf.lldxf.DXFBinaryTag(DXFTag)

DXFVertex

Represents a 2D or 3D vertex, stores only the group code of the x-component of the vertex, because the y-group-code is x-group-code + 10 and z-group-code id x-group-code+20, this is a rule that ALWAYS applies. This tag is mutable.
class ezdxf.lldxf.DXFVertex(DXFTag)
DXFVertex.code

DXF group code for the x-component (read only)

DXFVertex.value

x, y[, z] coordinates as array.array('d') object (read/write)

DXFVertex.__str__()
DXFVertex.__repr__()
DXFVertex.__getitem__()
DXFVertex.__iter__()
DXFVertex.dxftags()

Returns all vertex components as single DXFTag objects.

DXFVertex.dxfstr()

Returns the DXF string for all vertex components.

DXFVertex.clone()

Returns a clone of itself.

Tags

A list of DXF tags, 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(list)
Tags.from_text(text)

Constructor from DXF string.

Tags.strip(tags, codes)

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

Parameters:codes – iterable of group codes
Tags.get_handle()

Get DXF handle, raises DXFValueError if handle not exists.

Tags.replace_handle(new_handle)

Replace existing handle.

Parameters:new_handle – new handle as hex string, e.g. ‘FFFF’
Tags.dxftype()

Returns DXF type of entity, e.g. ‘LINE’.

Tags.has_tag(code)

Returns True if a DXF tag with group code code is present else False.

Parameters:code (int) – group code
Tags.get_first_value(code, default=DXFValueError)

Returns value of first DXF tag with given group code or default if default is not DXFValueError, else raises DXFValueError.

Parameters:
  • code (int) – group code
  • default – default value, DXFValueError raises an exception
Tags.get_first_tag(code, default=DXFValueError)

Returns first DXF tag with given group code or default if default is not DXFValueError, else raises DXFValueError.

Parameters:
  • code (int) – group code
  • default – default value, DXFValueError raises an exception
Tags.find_all(code)

Returns a list of DXF tag with given group code.

Parameters:code (int) – group code
Tags.tag_index(code, start=0, end=None)

Return index of first DXF tag with given group code.

Parameters:
  • code (int) – group code
  • start (int) – start index as int
  • end (int) – end index as int, if None end index is length of Tags
Tags.update(tag)

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

Parameters:tag – new DXF tag with code property
Tags.set_first(tag)

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

Parameters:tag – DXF tag
Tags.remove_tags(codes)

Remove all tags inplace with group codes specified in codes.

Parameters:codes – iterable of group codes
Tags.remove_tags_except(codes)

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

Parameters:codes – iterable of group codes
Tags.collect_consecutive_tags(codes, start=0, end=None)

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 (int) – start index
  • end (int) – end index, if None end index is length of Tags
Returns:

collected tags as Tags object

ExtendedTags

Represents the extended DXF tag structure introduced with DXF R13.
class ezdxf.lldxf.ExtendedTags

TODO

Packed Tags

The following tag types store multiple tags in one object to reduce the memory footprint.

TagList

Stores multiple tags with the same group code in a standard Python list.
class ezdxf.lldxf.TagList

TODO

TagArray

Stores multiple tags with the same group code in a array.array() object.
class ezdxf.lldxf.TagArray

TODO

TagDict

Stores multiple key/value tags with the same group code in a standard Python dict.
class ezdxf.lldxf.TagDict

TODO

VertexArray

Stores multiple vertex tags with the same group code in a array.array('d') object.
class ezdxf.lldxf.VertexArray

TODO