1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
# Copyright (c) 2022, Manfred Moitzi
# License: MIT License
import pathlib
import math
import ezdxf
from ezdxf.render.forms import torus
CWD = pathlib.Path("~/Desktop/Outbox").expanduser()
if not CWD.exists():
CWD = pathlib.Path(".")
def main():
doc = ezdxf.new()
doc.layers.new("form", dxfattribs={"color": 2})
normals_layer = doc.layers.new("normals", dxfattribs={"color": 6})
normals_layer.off()
msp = doc.modelspace()
closed_torus = torus(major_count=32, minor_count=16)
closed_torus.render_mesh(msp, dxfattribs={"layer": "form"})
closed_torus.render_normals(msp, dxfattribs={"layer": "normals"})
open_torus = torus(
major_count=16, minor_count=16, end_angle=math.pi, caps=True
)
open_torus.translate(5)
open_torus.render_mesh(msp, dxfattribs={"layer": "form"})
open_torus.render_normals(msp, dxfattribs={"layer": "normals"})
closed_tri_torus = torus(major_count=32, minor_count=16)
closed_tri_torus.translate(0, 5)
closed_tri_torus.render_mesh(msp, dxfattribs={"layer": "form"})
closed_tri_torus.render_normals(msp, dxfattribs={"layer": "normals"})
open_tri_torus = torus(
major_count=16, minor_count=16, end_angle=math.pi, caps=True
)
open_tri_torus.translate(5, 5)
open_tri_torus.render_mesh(msp, dxfattribs={"layer": "form"})
open_tri_torus.render_normals(msp, dxfattribs={"layer": "normals"})
doc.set_modelspace_vport(7, center=(2.5, 2.5))
doc.saveas(CWD / "torus.dxf")
if __name__ == "__main__":
main()
|