Reorder

Tools to reorder DXF entities by handle or a special sort handle mapping.

Such reorder mappings are stored only in layouts as Modelspace, Paperspace or BlockLayout, and can be retrieved by the method get_redraw_order().

Each entry in the handle mapping replaces the actual entity handle, where the “0” handle has a special meaning, this handle always shows up at last in ascending ordering.

ezdxf.reorder.ascending(entities: Iterable[DXFGraphic], mapping: dict | Iterable[tuple[str, str]] | None = None) Iterable[DXFGraphic]

Yields entities in ascending handle order.

The sort-handle doesn’t have to be the entity handle, every entity handle in mapping will be replaced by the given sort-handle, mapping is an iterable of 2-tuples (entity_handle, sort_handle) or a dict (entity_handle, sort_handle). Entities with equal sort-handles show up in source entities order.

Parameters:
  • entities – iterable of DXFGraphic objects

  • mapping – iterable of 2-tuples (entity_handle, sort_handle) or a handle mapping as dict.

ezdxf.reorder.descending(entities: Iterable[DXFGraphic], mapping: dict | Iterable[tuple[str, str]] | None = None) Iterable[DXFGraphic]

Yields entities in descending handle order.

The sort-handle doesn’t have to be the entity handle, every entity handle in mapping will be replaced by the given sort-handle, mapping is an iterable of 2-tuples (entity_handle, sort_handle) or a dict (entity_handle, sort_handle). Entities with equal sort-handles show up in reversed source entities order.

Parameters:
  • entities – iterable of DXFGraphic objects

  • mapping – iterable of 2-tuples (entity_handle, sort_handle) or a handle mapping as dict.