File: using_lineweight.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 (60 lines) | stat: -rw-r--r-- 1,628 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
54
55
56
57
58
59
60
# Copyright (c) 2018-2022, Manfred Moitzi
# License: MIT License
import pathlib
import ezdxf

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

# ------------------------------------------------------------------------------
# This example shows how to use lineweights.
#
# basic concept: https://ezdxf.mozman.at/docs/concepts/lineweights.html
# ------------------------------------------------------------------------------

LAYER_NAME = "Lines"

# line weight im mm times 100, e.g. 0.13mm = 13
# minimum line weight 0
# maximum line width 211
# all valid lineweights are stored in: ezdxf.const.VALID_DXF_LINEWEIGHTS
WEIGHTS = [13, 18, 20, 25, 35, 50, 70, 100, 200, -1, -3]


def lines_with_lineweight(msp, x1, x2):
    for index, lineweight in enumerate(WEIGHTS):
        y = index * 10
        msp.add_line(
            (x1, y),
            (x2, y),
            dxfattribs={
                "layer": LAYER_NAME,
                "lineweight": lineweight,
            },
        )


def lines_with_default_weight(msp, x1, x2):
    for index in range(len(WEIGHTS)):
        y = index * 10
        msp.add_line(
            (x1, y),
            (x2, y),
            dxfattribs={"layer": LAYER_NAME},
        )


doc = ezdxf.new("R2004")
# The CAD application should display lineweights:
doc.header["$LWDISPLAY"] = 1

msp = doc.modelspace()
lines_layer = doc.layers.new(LAYER_NAME)
# set default line width as enum
lines_layer.dxf.lineweight = 35

lines_with_lineweight(msp, x1=0, x2=100)
lines_with_default_weight(msp, x1=150, x2=250)

doc.saveas(CWD / "using_lineweight.dxf")