refactor example load_comments.py
-# Copyright (c) 2021, Manfred Moitzi
+# Copyright (c) 2021-2022, Manfred Moitzi
# License: MIT License
import sys
from ezdxf import comments
-if __name__ == "__main__":
+# ------------------------------------------------------------------------------
+# Ezdxf drops all comments from loaded DXF files.
+# This example shows how to load comments from DXF files if needed.
+#
+# docs: https://ezdxf.mozman.at/docs/comments.html
+# ------------------------------------------------------------------------------
+
+
+def main():
filename = sys.argv[1]
comment_collector = []
for code, value in comments.from_file(filename, codes={0, 5}):
- # get also handles and structure tags to associated prepending comments to DXF entities
+ # get also handles and structure tags to associated prepending comments
+ # to DXF entities
if code == 5:
handle = value
- print("Handle: {}".format(value))
+ print(f"Handle: {handle}")
print("Prepending comments:")
for comment in comment_collector:
print(comment)
@@ -21,3 +30,7 @@ if __name__ == "__main__":
comment_collector = []
elif code == 999:
comment_collector.append(value)
+
+
+if __name__ == "__main__":
+ main()
