refactor example leader.py
-# Copyright (c) 2019-2021 Manfred Moitzi
+# Copyright (c) 2019-2022 Manfred Moitzi
# License: MIT License
+import pathlib
import ezdxf
+from ezdxf.enums import TextEntityAlignment
+
+CWD = pathlib.Path("~/Desktop/Outbox").expanduser()
+if not CWD.exists():
+ CWD = pathlib.Path(".")
+
+# ------------------------------------------------------------------------------
+# This example adds a LEADER entity to the modelspace.
+#
+# docs: https://ezdxf.mozman.at/docs/dxfentities/leader.html
+# ------------------------------------------------------------------------------
doc = ezdxf.new("R2007", setup=True)
msp = doc.modelspace()
@@ -13,22 +25,19 @@ msp.add_leader(
vertices=[(10, 0), (12, 2), (14, 2)], override={"dimldrblk": "CLOSEDBLANK"}
)
-# I don't know how to to use text, tolerance or block reference annotations, but
-# you can draw the text as unrelated entity.
-
msp.add_text(
"Text",
dxfattribs={
"style": "OpenSans",
"height": 0.25,
},
-).set_pos((4, 5), align="MIDDLE_LEFT")
+).set_placement((4, 5), align=TextEntityAlignment.MIDDLE_LEFT)
msp.add_leader(vertices=[(0, 3), (2, 5), (4, 5)])
# For more information look at the Autodesk documentation.
# or https://atlight.github.io/formats/dxf-leader.html
-filename = "leader.dxf"
+filename = CWD / "leader.dxf"
doc.saveas(filename)
-print("drawing '%s' created.\n" % filename)
+print(f"drawing {filename} created.")
