Text To Polylines Sample
Using ezdxf’s make_paths_from_str, works with Unicode.
import traceback
from pyrx import Ap, Db, Ge, Ed
from ezdxf import fonts
from ezdxf.addons import text2path
@Ap.Command()
def doit1():
try:
db = Db.curDb()
text_str = "Hello World"
font_face = fonts.fonts.find_best_match(family="Arial", style="Italic")
paths = text2path.make_paths_from_str(text_str, font_face, size=db.textsize())
for p in paths:
vertices = list(p.flattening(distance=0.01))
if len(vertices) < 2:
continue
pl = Db.Polyline()
for idx, pt in enumerate(vertices):
pl.addVertexAt(idx, Ge.Point2d(pt.x, pt.y))
db.addToCurrentspace(pl)
except Exception as e:
traceback.print_exc()
@Ap.Command()
def doit2():
try:
db = Db.curDb()
text_str = "你好,世界" # "Hello, World"
font_face = fonts.fonts.find_best_match(family="Microsoft YaHei")
paths = text2path.make_paths_from_str(text_str, font_face, size=db.textsize())
for p in paths:
vertices = list(p.flattening(distance=0.01))
if len(vertices) < 2:
continue
pl = Db.Polyline()
for idx, pt in enumerate(vertices):
pl.addVertexAt(idx, Ge.Point2d(pt.x, pt.y))
db.addToCurrentspace(pl)
except Exception as e:
traceback.print_exc()
0
Comments
-
Just some comments.
Worst Txtexp built in.
Your code may be way better have another post to answer that needs exploded text. Will try it.
TXT2GEOM by Seant has been around for a long time and does a good job. Its a install package not a lisp. Pretty sure had a Bricscad version trying to find it.
0 -
Pretty much the same as Txtexp except you don’t have to create the mtext first. Yeah, Sean’s routine is first class, not sure it runs as it was in .net 3 or 4..
Run pip install -U cad-pyrx so you’re on the latest package
0


