What's the format for RichText text?

If I wanted to script portion of text object’s text bold for example.

Hello - it looks like this may be accessible from RhinoCommon but it may not be super easy to use - just at a quick look… @Alain - can you help here at all?

-Pascal

Hi @Asterisk, below seems to work:

import Rhino
import scriptcontext

def DoSomething():
    te = Rhino.Geometry.TextEntity.CreateWithRichText(
                                            r"Next word is \b bold \b0",
                                            Rhino.Geometry.Plane.WorldXY,
                                            scriptcontext.doc.DimStyles.Current,
                                            False,
                                            0.0,
                                            0.0
                                            )
    
    scriptcontext.doc.Objects.AddText(te)
    scriptcontext.doc.Views.Redraw()

DoSomething()

Note: Font and text size is controlled through the dimension style.

_
c.

3 Likes

In case you want to read more about RTF: Rich Text Format - Wikipedia

1 Like
import Rhino
import scriptcontext

def DoSomething():
    name = "name"
    desc = "desc"
    loc = "loc"
    msr = 12.1
    units = "LF\n"
    so = "stretch-out"
    
   txt = r"{\b " + name + "}" + "\n(" + desc + ")\n\nLOCATION:\n" + loc + "\n\n" + str(int(msr)) + units + so + "\n\n\nQTY:______       LENGTH:______"
    te = Rhino.Geometry.TextEntity.CreateWithRichText(
                                            txt,
                                            Rhino.Geometry.Plane.WorldXY,
                                            scriptcontext.doc.DimStyles.Current,
                                            False,
                                            0.0,
                                            0.0
                                            )
    
    scriptcontext.doc.Objects.AddText(te)
    scriptcontext.doc.Views.Redraw()

DoSomething()

This works.