How to render text-paths as HATCH entities #742
-
Implement similar functions #715
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
You have to render the text as HATCH entities. The first example shows how to render HATCHES with solid filling: import ezdxf
from ezdxf.addons import text2path
from ezdxf.tools import fonts
from ezdxf.math import Matrix44
from ezdxf import zoom
doc = ezdxf.new()
msp = doc.modelspace()
hatches = text2path.make_hatches_from_str(
"厂牌AAA123",
font=fonts.FontFace(family="SimSun"),
size=4,
)
m = Matrix44.translate(2, 1.5, 0)
for hatch in hatches:
hatch.transform(m)
hatch.set_solid_fill(color=1, style=0)
msp.add_entity(hatch)
zoom.extents(msp)
doc.saveas("text2solid_hatch.dxf") The ...
for hatch in hatches:
hatch.transform(m)
hatch.set_pattern_fill(name="ANSI31", color=1, scale=0.02, angle=-45, style=0)
msp.add_entity(hatch)
... You have more control over the HATCH pattern by defining you own custom pattern: ...
# ANSI31 definition: [angle, base_point, offset, dash_length_items]
# "ANSI31": [[45.0, (0.0, 0.0), (-2.2450640303, 2.2450640303), []]]
OFFSET = (0, 0.05) # (x, y)
SOLID = [] # continuous line
DASHED = [0.5, -0.3] # > 0 line, < 0 gap, 0 = point
MY_PATTERN = [
[0.0, (0.0, 0.0), OFFSET, SOLID], # a single hatch line definition
]
for hatch in hatches:
hatch.transform(m)
hatch.set_pattern_fill(
name="MY_PATTERN",
color=1,
style=0,
pattern_type=2,
definition=MY_PATTERN,
)
msp.add_entity(hatch)
... For adding the outline path you have to render the text a second time as paths as in your original script. |
Beta Was this translation helpful? Give feedback.
You have to render the text as HATCH entities. The first example shows how to render HATCHES with solid filling:
The
HATCH
entity can be filled with predefined patterns, but this involves much guessing: