File: spline_from_ellipse.py

package info (click to toggle)
ezdxf 1.4.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 104,528 kB
  • sloc: python: 182,341; makefile: 116; lisp: 20; ansic: 4
file content (39 lines) | stat: -rw-r--r-- 934 bytes parent folder | download
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
# Copyright (c) 2020-2021, Manfred Moitzi
# License: MIT License
import pathlib
import math
import ezdxf
from ezdxf import zoom

CWD = pathlib.Path("~/Desktop/Outbox").expanduser()
if not CWD.exists():
    CWD = pathlib.Path(".")

# ------------------------------------------------------------------------------
# This example shows how to convert an ELLIPSE into a SPLINE.
# ------------------------------------------------------------------------------


def main():
    doc = ezdxf.new()
    msp = doc.modelspace()

    ellipse = msp.add_ellipse(
        center=(0, 0),
        major_axis=(1, 0),
        ratio=0.5,
        start_param=0,
        end_param=math.tau,
        dxfattribs={"layer": "ellipse"},
    )

    spline = ellipse.to_spline(replace=False)
    spline.dxf.layer = "B-spline"
    spline.dxf.color = 1

    zoom.extents(msp)
    doc.saveas(CWD / "spline_from_ellipse.dxf")


if __name__ == "__main__":
    main()