TextEntity, Get Font of the text

Hello,
I wonder if it is possible to get the actual text font from textEntity.

Thanks in advance.

HI Gustavo
You can try this code:

var text = Rhino.RhinoDoc.ActiveDoc.Objects.Find(guid) as Rhino.DocObjects.TextObject;
if(text != null)
{
  A = text.TextGeometry.Font.LogfontName;
}

Hi NARUTO,

Sorry, but throws this error:
"|Error|CS1061|‘TextEntity’ does not contain a definition for ‘Font’ and no extension method ‘Font’ accepting a first argument of type ‘TextEntity’ could be found (are you missing a using directive or an assembly reference?)

Hi,
Are you using Rhino 5? In that case it’s very different.
Something like:

var font = doc.Fonts(text.TextGeometry.FontIndex)

Hi Alain,

Yes, I’m using Rhino 5.
I did it:

var font = doc.Fonts[obj.TextGeometry.FontIndex].FaceName;

Thanks.

For what it’s worth, Rhino 6 makes working/scripting with fonts quite a bit better. One thing we came across, (at least the way we were doing it), was getting the gh preview text to properly honor the referenced text’s justification style. We took kind of a long walk, but came to a reasonable solution, (for now, we may re-write it later). It involved recreating the text entity with some attributes of the original text entity). This seemed to be the trick to get the justification correct. This is in python, but maybe this snippet helps. (we also grabbed the surfaces and outline curves of the text entity, those methods were not available in R5).
Original text objects referenced from Rhino, with properties set in Rhino.

        for counter, i in enumerate(DisplayText):
            newText = rg.TextEntity.Create(i, plane[counter], DimStyle[counter], False, bboxW[counter], 0)
            newText.Font = Rhino.DocObjects.Font(Font)
            self.Crvs.append(newText.CreateCurves(newText.DimensionStyle, False, newText.TextHeight, 0))
            self.Srfs.append(newText.CreateSurfaces(newText.DimensionStyle, 1, 0))
            self.DisplayText.append(newText)
            self.bb.Union(newText.GetBoundingBox(True))
        return th.list_to_tree(self.Crvs), th.list_to_tree(self.Srfs)

Hi
Thanks @603419608 for your solution. I managed to retrieve Font Family and Font Face Name with

TextObject txt = ro as TextObject;
font = txt.TextGeometry.Font.FamilyName;
name = txt.TextGeometry.Font.FaceName;

Is there a way to retrieve this information somehow in python way without the workaround provided by @chanley for further processing? I miss these two outputs by the “TextObjInfo” node in Human plugin…

Thanks in advance!

Hi @nevesp82,

How about something like this?

import Rhino

def __textobject_filter(rhObject, geometry, componentIndex):
    return isinstance(rhObject, Rhino.DocObjects.TextObject)

def test_textobject_font():
    go = Rhino.Input.Custom.GetObject()
    go.SetCommandPrompt("Select text")
    go.SetCustomGeometryFilter(__textobject_filter)
    go.Get()
    if go.CommandResult() != Rhino.Commands.Result.Success:
        return
    
    rhObject = go.Object(0).Object()
    if isinstance(rhObject, Rhino.DocObjects.TextObject):
        family_name = rhObject.TextGeometry.Font.FamilyName
        face_name = rhObject.TextGeometry.Font.FaceName
        print(family_name)
        print(face_name)
        
if( __name__ == "__main__" ):
    test_textobject_font()

– Dale

Thanks @dale this helps!