# Transform¶

New in version 1.1.

This module provides functions to apply transformations to multiple DXF entities inplace or to virtual copies of that entities in a convenient and safe way:

```import math

import ezdxf
from ezdxf import transform

doc = ezdxf.readfile("my.dxf")
msp = doc.modelspace()

log = transform.inplace(msp, m=transform.Matrix44.rotate_z(math.pi/2))

# or more simple
log = transform.z_rotate(msp, math.pi/2)
```

All functions handle errors by collecting them in an logging object without raising an error. The input entities are an iterable of `DXFEntity`, which can be any layout, `EntityQuery` or just a list/sequence of entities and virtual entities are supported as well.

 `inplace` Transforms the given entities inplace by the transformation matrix m, non-uniform scaling is supported. `copies` Copy entities and transform them by matrix m. `translate` Translates (moves) entities inplace by the offset vector. `scale_uniform` Scales entities inplace by a factor in all axis. `scale` Scales entities inplace by the factors sx in x-axis, sy in y-axis and sz in z-axis. `x_rotate` Rotates entities inplace by angle in radians about the x-axis. `y_rotate` Rotates entities inplace by angle in radians about the y-axis. `z_rotate` Rotates entities inplace by angle in radians about the x-axis. `axis_rotate` Rotates entities inplace by angle in radians about the rotation axis starting at the origin pointing in axis direction.
ezdxf.transform.inplace(entities: Iterable[DXFEntity], m: Matrix44)

Transforms the given entities inplace by the transformation matrix m, non-uniform scaling is supported. The function converts circular arcs into ellipses to perform non-uniform scaling. The function logs errors and does not raise errors for unsupported entities or transformation errors, see enum `Error`.

Important

The `inplace()` function does not support type conversion for virtual entities e.g. non-uniform scaling for CIRCLE, ARC or POLYLINE with bulges, see also function `copies()`.

ezdxf.transform.copies(entities: Iterable[DXFEntity], m: Matrix44 | None = None) Tuple[Logger, List[DXFEntity]]

Copy entities and transform them by matrix m. Does not raise any exception and ignores all entities that cannot be copied or transformed. Just copies the input entities if matrix m is `None`. Returns a tuple of `Logger` and a list of transformed virtual copies. The function supports virtual entities as input and converts circular arcs into ellipses to perform non-uniform scaling.

ezdxf.transform.translate(entities: Iterable[DXFEntity], offset: UVec)

Translates (moves) entities inplace by the offset vector.

ezdxf.transform.scale_uniform(entities: Iterable[DXFEntity], factor: float)

Scales entities inplace by a factor in all axis. Scaling factors smaller than `MIN_SCALING_FACTOR` are ignored.

ezdxf.transform.scale(entities: Iterable[DXFEntity], sx: float, sy: float, sz: float)

Scales entities inplace by the factors sx in x-axis, sy in y-axis and sz in z-axis. Scaling factors smaller than `MIN_SCALING_FACTOR` are ignored.

Important

same limitations for virtual entities as the `inplace()` function

ezdxf.transform.x_rotate(entities: Iterable[DXFEntity], angle: float)

Rotates entities inplace by angle in radians about the x-axis.

ezdxf.transform.y_rotate(entities: Iterable[DXFEntity], angle: float)

Rotates entities inplace by angle in radians about the y-axis.

ezdxf.transform.z_rotate(entities: Iterable[DXFEntity], angle: float)

Rotates entities inplace by angle in radians about the x-axis.

ezdxf.transform.axis_rotate(entities: Iterable[DXFEntity], axis: UVec, angle: float)

Rotates entities inplace by angle in radians about the rotation axis starting at the origin pointing in axis direction.

ezdxf.transform.MIN_SCALING_FACTOR

Minimal scaling factor: 1e-12

class ezdxf.transform.Error
NONE

No error, same as a boolean `False`, this allows check `if error: ...`

COPY_NOT_SUPPORTED

Entity without copy support.

TRANSFORMATION_NOT_SUPPORTED

Entity without transformation support.

NON_UNIFORM_SCALING_ERROR

Circular arcs (CIRCLE, ARC, bulges in POLYLINE and LWPOLYLINE entities) cannot be scaled non-uniformly.

INSERT_TRANSFORMATION_ERROR

INSERT entities cannot represent a non-orthogonal target coordinate system. Maybe exploding the INSERT entities (recursively) beforehand can solve this issue, see function `ezdxf.disassemble.recursive_decompose()`.

VIRTUAL_ENTITY_NOT_SUPPORTED

Transformation not supported for virtual entities e.g. non-uniform scaling for CIRCLE, ARC or POLYLINE with bulges

class ezdxf.transform.Logger

A `Sequence` of errors as `Logger.Entry` instances.

class Entry

Named tuple representing a logger entry.

error

`Error` enum

msg

error message as string

entity

DXF entity which causes the error

__len__() int

Returns the count of error entries.

__getitem__(index: int)

Returns the error entry at index.

__iter__() Iterator[Entry]

Iterates over all error entries.

messages() list[str]

Returns all error messages as list of strings.