File: using_ocs_and_ucs.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 (46 lines) | stat: -rw-r--r-- 1,337 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
40
41
42
43
44
45
46
# Copyright (c) 2019-2022, Manfred Moitzi
# License: MIT License
import pathlib
import ezdxf
from ezdxf.math import UCS, OCS

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

# ------------------------------------------------------------------------------
# This example shows how to place a 2D entity in 3D by using OCS coordinates.
#
# basic concept OCS: https://ezdxf.mozman.at/docs/concepts/ocs.html
# OCS: https://ezdxf.mozman.at/docs/math/core.html#ocs-class
# UCS: https://ezdxf.mozman.at/docs/math/core.html#ucs-class
# tutorial: https://ezdxf.mozman.at/docs/tutorials/ucs_transform.html
# ------------------------------------------------------------------------------


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

    origin = (3, 3, 3)
    axis = (1, 0, -1)
    def_point = (3, 10, 4)

    ucs = UCS.from_z_axis_and_point_in_yz(origin, axis=axis, point=def_point)
    ucs.render_axis(msp, length=5)
    msp.add_point(location=def_point, dxfattribs={"color": 2})

    ocs = OCS(ucs.uz)
    msp.add_circle(
        center=ocs.from_wcs(origin),
        radius=1,
        dxfattribs={
            "color": 2,
            "extrusion": ucs.uz,
        },
    )
    doc.saveas(filename)


if __name__ == "__main__":
    main(CWD / "using_ucs.dxf")