refactor example sweep_profile.py
@@ -12,11 +12,8 @@ if not CWD.exists():
CWD = pathlib.Path(".")
DEBUG_COLOR = ezdxf.colors.CYAN
-doc = ezdxf.new()
-doc.layers.add("DEBUG", color=DEBUG_COLOR)
-msp = doc.modelspace()
-
+def main(filepath):
def add_debug_profiles(profiles, sweeping_path):
attribs = {"layer": "DEBUG"}
msp.add_polyline3d(sweeping_path, dxfattribs=attribs)
@@ -29,6 +26,9 @@ def add_debug_profiles(profiles, sweeping_path):
for s, e in zip(p0, p1):
msp.add_line(s, e, dxfattribs=attribs)
+ doc = ezdxf.new()
+ doc.layers.add("DEBUG", color=DEBUG_COLOR)
+ msp = doc.modelspace()
circle = list(forms.circle(8))
p0 = path.Path()
@@ -53,13 +53,18 @@ offset = 10, 10, 0
add_debug_profiles(
[
list(forms.translate(p, offset))
- for p in forms.debug_sweep_profiles(square, sweeping_path, close=True)
+ for p in forms.debug_sweep_profiles(
+ square, sweeping_path, close=True
+ )
],
list(forms.translate(sweeping_path, offset)),
)
-
mesh.translate(*offset)
mesh.render_mesh(msp, dxfattribs={"color": ezdxf.colors.YELLOW})
-doc.saveas(CWD / "sweep_profile.dxf")
+ doc.saveas(filepath)
+
+
+if __name__ == "__main__":
+ main(CWD / "sweep_profile.dxf")
