See this:
If you really want to write your own text-to-mesh component, here’s the function that was used to make text meshes in Legacy:
import Rhino as rc
import System
def textJustificationEnumeration(self, justificationIndex):
#justificationIndices:
# 0 - bottom left (default)
# 1 - bottom center
# 2 - bottom right
# 3 - middle left
# 4 - center
# 5 - middle right
# 6 - top left
# 7 - top middle
# 8 - top right
constantsList = [0, 2, 4, 131072, 131074, 131076, 262144, 262146, 262148]
try:
justificationConstant = constantsList[justificationIndex]
except:
# if 0 < justificationIndex > 8
justificationConstant = 0
textJustification = System.Enum.ToObject(rc.Geometry.TextJustification, justificationConstant)
return textJustification
def text2srf(text, textPt, font = 'Verdana', textHeight = 20, bold = False, plane = None, justificationIndex = 0):
# Thanks to Giulio Piacentino for his version of text to curve
textSrfs = []
textJustification = textJustificationEnumeration(justificationIndex)
planeCheck = False
scale = rc.RhinoDoc.ActiveDoc.DimStyles.CurrentDimensionStyle.DimensionScale
for n in range(len(text)):
if plane == None or planeCheck == True:
plane = rc.Geometry.Plane(textPt[n], rc.Geometry.Vector3d(0,0,1))
planeCheck = True
if type(text[n]) is not str:
preText = rc.RhinoDoc.ActiveDoc.Objects.AddText(`text[n]`, plane, textHeight, font, bold, False, textJustification)
else:
preText = rc.RhinoDoc.ActiveDoc.Objects.AddText( text[n], plane, textHeight, font, bold, False, textJustification)
postText = rc.RhinoDoc.ActiveDoc.Objects.Find(preText)
TG = postText.Geometry
crvs = TG.Explode()
# join the curves
joindCrvs = rc.Geometry.Curve.JoinCurves(crvs)
# create the surface
srfs = rc.Geometry.Brep.CreatePlanarBreps(joindCrvs)
extraSrfCount = 0
# = generate 2 surfaces
if "=" in text[n]: extraSrfCount += -1
if ":" in text[n]: extraSrfCount += -1
if srfs:
if len(text[n].strip()) != len(srfs) + extraSrfCount:
# project the curves to the place in case number of surfaces
# doesn't match the text
projectedCrvs = []
for crv in joindCrvs:
projectedCrvs.append(rc.Geometry.Curve.ProjectToPlane(crv, plane))
srfs = rc.Geometry.Brep.CreatePlanarBreps(projectedCrvs)
#Mesh the surfcaes.
meshSrfs = []
for srf in srfs:
srf.Flip()
try:
meshSrf = rc.Geometry.Mesh.CreateFromBrep(srf, rc.Geometry.MeshingParameters.Coarse)[0]
except TypeError:
# pass very small surfaces
continue
else:
meshSrf.VertexColors.CreateMonotoneMesh(System.Drawing.Color.Black)
meshSrfs.append(meshSrf)
textSrfs.append(meshSrfs)
rc.RhinoDoc.ActiveDoc.Objects.Delete(postText, True) # find and delete the text
return textSrfs