File: mtext_in_yz_plane.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 (53 lines) | stat: -rw-r--r-- 1,643 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
47
48
49
50
51
52
53
# Copyright (c) 2017-2022 Manfred Moitzi
# License: MIT License
import pathlib
import ezdxf
from ezdxf.math import UCS

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

# ------------------------------------------------------------------------------
# This example shows how to place a MTEXT entity in 3D space.
#
# docs: https://ezdxf.mozman.at/docs/dxfentities/mtext.html
# tutorial: https://ezdxf.mozman.at/docs/tutorials/mtext.html
# ------------------------------------------------------------------------------


def place_by_extrusion_vector():
    doc = ezdxf.new("R2000")
    modelspace = doc.modelspace()
    modelspace.add_mtext(
        "This is a text in the YZ-plane",
        dxfattribs={
            "width": 12,  # reference rectangle width
            "text_direction": (0, 1, 0),  # write in y direction
            "extrusion": (1, 0, 0),  # normal vector of the text plane
        },
    )
    doc.saveas(CWD / "mtext_extrusion_vector.dxf")


def place_by_ucs():
    doc = ezdxf.new("R2000")
    modelspace = doc.modelspace()
    # place the MTEXT in the xy-plane of the UCS
    mtext = modelspace.add_mtext(
        "This is a text in the YZ-plane",
        dxfattribs={
            "width": 12,  # reference rectangle width
            "text_direction": (1, 0, 0),  # write in x direction
        },
    )
    # define the ucs:
    # x-axis = WCS y-axis; z-axis = WCS x-axis
    ucs = UCS(ux=(0, 1, 0), uz=(1, 0, 0))
    mtext.transform(ucs.matrix)
    doc.saveas(CWD / "mtext_ucs.dxf")


if __name__ == '__main__':
    place_by_extrusion_vector()
    place_by_ucs()