refactor transform_modelspace.py
-# Copyright (c) 2021 Manfred Moitzi
+# Copyright (c) 2021-2022 Manfred Moitzi
# License: MIT License
+import pathlib
import ezdxf
from ezdxf.math import Matrix44, TransformError
from ezdxf.layouts import BaseLayout
-from pathlib import Path
-DIR = Path("~/Desktop/Outbox").expanduser()
+
+CWD = pathlib.Path("~/Desktop/Outbox").expanduser()
+if not CWD.exists():
+ CWD = pathlib.Path(".")
+
+# ------------------------------------------------------------------------------
+# This example shows how to transform all entities of a layout by the
+# general transformation interface.
+# docs: https://ezdxf.mozman.at/docs/dxfentities/dxfgfx.html#ezdxf.entities.DXFGraphic.transform
+# ------------------------------------------------------------------------------
+
EXAMPLE = (
ezdxf.options.test_files_path / "CADKitSamples" / "AEC Plan Elev Sample.dxf"
)
+INCH_TO_MM = 25.4
def transform_layout(layout: BaseLayout, m: Matrix44) -> None:
@@ -21,6 +32,5 @@ def transform_layout(layout: BaseLayout, m: Matrix44) -> None:
doc = ezdxf.readfile(EXAMPLE)
-INCH_TO_MM = 25.4
transform_layout(doc.modelspace(), Matrix44.scale(INCH_TO_MM))
-doc.saveas(DIR / "scaled.dxf")
+doc.saveas(CWD / "scaled.dxf")
