forked from mozman/ezdxf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdump_hatch_pattern.py
42 lines (30 loc) · 1 KB
/
dump_hatch_pattern.py
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
# Copyright (c) 2011-2020, Manfred Moitzi
# License: MIT License
import sys
from pathlib import Path
import ezdxf
def main(filename):
doc = ezdxf.readfile(filename)
msp = doc.modelspace()
hatches = msp.query("HATCH[solid_fill==0]")
filename.with_suffix(".py")
dump_pattern(filename.with_suffix(".py"), hatches)
def dump_pattern(filename, hatches):
with open(filename, "wt") as f:
f.write(FILE_HEADER)
for hatch in hatches:
f.write(get_pattern_definition_string(hatch))
f.write(FILE_TAIL)
FILE_HEADER = """# DXF pattern definition file
# Do not edit this file, because this file was generated by 'dump_hatch_pattern.py'
# 'dump_hatch_pattern.py' is part of the Python package 'ezdxf'
Pattern = {
"""
FILE_TAIL = "}\n"
def get_pattern_definition_string(hatch):
name = hatch.dxf.pattern_name
with hatch.edit_pattern() as p:
pattern = str(p)
return "'{}': {},\n".format(name, pattern)
if __name__ == "__main__":
main(Path(sys.argv[1]))