File: create_hatch_pattern_examples.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 (37 lines) | stat: -rw-r--r-- 1,230 bytes parent folder | download | duplicates (2)
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
#  Copyright (c) 2020, Manfred Moitzi
#  License: MIT License

import ezdxf
from ezdxf.tools import pattern
from ezdxf.render.forms import square, translate

HEIGHT = 300


def add_predefined_hatch_pattern(msp, cols, size, gap, scale):
    for index, name in enumerate(pattern.ISO_PATTERN.keys()):
        x = (index % cols) * (size + gap)
        y = (index // cols) * (size + gap)
        boundary = list(translate(square(size), (x, HEIGHT - y)))
        msp.add_lwpolyline(boundary, close=True, dxfattribs={"layer": "LINE"})
        hatch = msp.add_hatch(dxfattribs={"layer": "HATCH"})
        hatch.set_pattern_fill(name=name, scale=scale)
        hatch.paths.add_polyline_path(boundary, is_closed=True)


if __name__ == "__main__":
    # Imperial: Inch
    doc = ezdxf.new(units=1)
    add_predefined_hatch_pattern(
        doc.modelspace(), cols=10, size=10, gap=1, scale=4
    )
    doc.set_modelspace_vport(HEIGHT, (30, HEIGHT / 2))
    doc.saveas("hatch_pattern_imperial.dxf")

    # ISO: Meter
    doc = ezdxf.new(units=6)
    add_predefined_hatch_pattern(
        doc.modelspace(), cols=10, size=10, gap=1, scale=0.25
    )
    doc.set_modelspace_vport(HEIGHT, (30, HEIGHT / 2))
    doc.saveas("hatch_pattern_iso.dxf")