Transform¶
Added 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.
Transforms the given entities inplace by the transformation matrix m, nonuniform scaling is supported. 

Copy entities and transform them by matrix m. 

Translates (moves) entities inplace by the offset vector. 

Scales entities inplace by a factor in all axis. 

Scales entities inplace by the factors sx in xaxis, sy in yaxis and sz in zaxis. 

Rotates entities inplace by angle in radians about the xaxis. 

Rotates entities inplace by angle in radians about the yaxis. 

Rotates entities inplace by angle in radians about the xaxis. 

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) Logger ¶
Transforms the given entities inplace by the transformation matrix m, nonuniform scaling is supported. The function converts circular arcs into ellipses to perform nonuniform scaling. The function logs errors and does not raise errors for unsupported entities or transformation errors, see enum
Error
.
 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 ofLogger
and a list of transformed virtual copies. The function supports virtual entities as input and converts circular arcs into ellipses to perform nonuniform scaling.
 ezdxf.transform.translate(entities: Iterable[DXFEntity], offset: UVec) Logger ¶
Translates (moves) entities inplace by the offset vector.
 ezdxf.transform.scale_uniform(entities: Iterable[DXFEntity], factor: float) Logger ¶
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) Logger ¶
Scales entities inplace by the factors sx in xaxis, sy in yaxis and sz in zaxis. 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) Logger ¶
Rotates entities inplace by angle in radians about the xaxis.
 ezdxf.transform.y_rotate(entities: Iterable[DXFEntity], angle: float) Logger ¶
Rotates entities inplace by angle in radians about the yaxis.
 ezdxf.transform.z_rotate(entities: Iterable[DXFEntity], angle: float) Logger ¶
Rotates entities inplace by angle in radians about the xaxis.
 ezdxf.transform.axis_rotate(entities: Iterable[DXFEntity], axis: UVec, angle: float) Logger ¶
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: 1e12
 class ezdxf.transform.Error¶
 NONE¶
No error, same as a boolean
False
, this allows checkif 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 nonuniformly.
 INSERT_TRANSFORMATION_ERROR¶
INSERT entities cannot represent a nonorthogonal 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. nonuniform scaling for CIRCLE, ARC or POLYLINE with bulges
 class ezdxf.transform.Logger¶
A
Sequence
of errors asLogger.Entry
instances. class Entry¶
Named tuple representing a logger entry.
 msg¶
error message as string
 entity¶
DXF entity which causes the error
 __len__() int ¶
Returns the count of error entries.
 messages() list[str] ¶
Returns all error messages as list of strings.