Convert text objects to mesh

Hi just wanted to know if there was a way of converting text objects (such as those that are produced in legends and graph labels) into meshes within grasshopper without having to manually convert them through rhino? I know they used to do this previously and the project i’m working on requires the text to be in mesh form

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

Hi Chris, thanks for your response.
I tried out the GHPython function you provided.
In my first attempt i realised i needed to set the text points.
In my second attempt i set the text points as one of the inputs but this wasn’t accepted within the function.
In my third attempt I was able to write the text points into the code but now have the trouble of needing to extract the original text points for reference. How might i do this? Please see attached for an example file.


Processing: Convert text to mesh example file.gh…

@amynuccio ,

It seems you made your post before your .gh file finished uploading. If you re-post it, I will take a look. You can use the native Grasshopper Bounding Box component on the text output from the LBT component in order to get a base point for the text.

Convert text to mesh example file.gh (54.4 KB)