-
I added hatches in .pat in support folder, but when I use this hatches in script, Autocad render it as ANSI31 |
Beta Was this translation helpful? Give feedback.
Answered by
mozman
Feb 24, 2024
Replies: 2 comments
-
I don't understand what you did, but adding a pattern file to a directory doesn't do anything. Hatch pattern are stored in the |
Beta Was this translation helpful? Give feedback.
0 replies
-
The following script shows how to load patterns from a import ezdxf
from ezdxf.tools import pattern
from ezdxf import zoom
EXAMPLE = """; a pattern file
*SOLID, Solid fill
45, 0,0, 0,.125
*ANSI31, ANSI Iron, Brick, Stone masonry
45, 0,0, 0,.125
*ANSI32, ANSI Steel
45, 0,0, 0,.375
45, .176776695,0, 0,.375
*ANSI33, ANSI Bronze, Brass, Copper
45, 0,0, 0,.25
45, .176776695,0, 0,.25, .125,-.0625
*ANSI34, ANSI Plastic, Rubber
45, 0,0, 0,.75
45, .176776695,0, 0,.75
45, .353553391,0, 0,.75
45, .530330086,0, 0,.75
"""
def load_pattern_from_file():
doc = ezdxf.new("R2010") # create a new DXF drawing (AutoCAD 2010)
msp = doc.modelspace() # we are working in model space
hatch = msp.add_hatch() # by default a SOLID fill
# load your pattern file from the file system as string:
# with open("pattern_file.pat", "rt") as fp:
# EXAMPLE = fp.read()
patterns = pattern.parse(EXAMPLE)
hatch.set_pattern_fill(
"MyPattern",
color=7,
angle=0,
scale=1.0,
style=0,
pattern_type=0,
# pattern name without the preceding asterisk
definition=patterns["ANSI34"],
)
points = [(0, 0), (10, 0), (10, 10), (0, 10)]
hatch.paths.add_polyline_path(points)
msp.add_lwpolyline(points, close=True, dxfattribs={"color": 1})
zoom.extents(msp)
doc.saveas("loaded_pattern_from_file.dxf")
if __name__ == "__main__":
load_pattern_from_file() |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
amoudaria
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The following script shows how to load patterns from a
.pat
files: