refactor example dxf2code.py
-from pathlib import Path
+# Copyright (c) 2022, Manfred Moitzi
+# License: MIT License
+import pathlib
import ezdxf
from ezdxf.addons.dxf2code import entities_to_code
-FILENAME = "A_000217"
-CADKIT = Path(ezdxf.EZDXF_TEST_FILES) / "CADKitSamples"
-OUTBOX = Path("~/Desktop/Outbox").expanduser()
+CWD = pathlib.Path("~/Desktop/Outbox").expanduser()
+if not CWD.exists():
+ CWD = pathlib.Path(".")
+
+# ------------------------------------------------------------------------------
+# This example shows how to export DXF entities from modelspace as Python code.
+# ------------------------------------------------------------------------------
+FILENAME = "A_000217"
+CADKIT = ezdxf.options.test_files_path / "CADKitSamples"
DXF_FILE = CADKIT / f"{FILENAME}.dxf"
-SOURCE_CODE_FILE = OUTBOX / f"{FILENAME}.py"
+SOURCE_CODE_FILE = CWD / f"{FILENAME}.py"
+
+def main():
doc = ezdxf.readfile(DXF_FILE)
msp = doc.modelspace()
@@ -26,3 +36,7 @@ with open(SOURCE_CODE_FILE, mode="wt") as f:
f.write("\n")
print("done.")
+
+
+if __name__ == "__main__":
+ main()
