Rhino.AddText - masking?

I’m wondering if there is a way to have text added with the Rhino.AddText command come in with Masking set to background? There doesn’t appear to be the option in the Rhinoscript command, unless I’m missing.
Or even any command where I might be able to select the last object and change the masking?
Thanks,
Adrian

Yes, looks like the text mask is not exposed in Rhinoscript. It is exposed in RhinoCommon, so you could program it using a Python script. Otherwise, with vb Rhinoscript, probably easiest just to script Rhino.Command(“Text…”) with the needed options including mask…

HTH, --Mitch

Thanks Mitch, I’ve had a couple of looks at Python, following your recommendation a couple of months back. I have so much RhinoScript code developed over many years, which makes the change challenging!
Might give it another go and see if I can get this working. Worth the learning exercise, and if it is a success that is even better :smile:

Cheers,
Adrian

I’ve added a wish list item for RhinoScript.

http://mcneel.myjetbrains.com/youtrack/issue/RH-30513

Thanks Dale

Just playing with adding a text with a mask via Python/RhinoCommon. Have a couple of questions…

How does one specify a font (if possible)? I see TextEntity.FontIndex, but unfortunately doesn’t work, because scriptcontext.doc.Fonts only has Arial by default, so no matter what I put for FontIndex, it’s the same…

Second is the specification of MaskOffset. The SDK help simply specifies that it wants a “double”, so I assumed at first that it was in file units, but no… After some experimentation it appears that it’s a multiplier of the text height. Can the Help at least be made clearer on that?

Thanks, --Mitch

Test code (edited to include answers below):

import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino, System

def TestAddTextWithMask():
    user_text=rs.GetString("Enter your text")
    if not user_text: return
    ht=rs.GetReal("Text height?",5,minimum=0)
    if not ht: return
    mask_offset=rs.GetReal("Mask offset?",2,minimum=0)
    if mask_offset is None: return
    ins_pt=rs.GetPoint("Pick point for insertion")
    if not ins_pt: return
    
    mask_offset=mask_offset/ht
    plane=Rhino.Geometry.Plane.WorldXY
    plane.Origin=ins_pt
    
    #arguments - font name, bold, italic
    #if font is not found, Arial will be used
    fi = sc.doc.Fonts.FindOrCreate("Courier New", True, False)

    te=Rhino.Geometry.TextEntity()
    te.Text=user_text
    te.TextHeight=ht
    te.MaskEnabled=True
    te.MaskUsesViewportColor=False
    te.MaskColor=System.Drawing.Color.Red
    te.MaskOffset=mask_offset
    te.Plane=plane
    te.FontIndex=fi
    
    oa=Rhino.DocObjects.ObjectAttributes()
    oa.ObjectColor=System.Drawing.Color.Black
    oa.ColorSource=Rhino.DocObjects.ObjectColorSource.ColorFromObject
    
    sc.doc.Objects.AddText(te,oa)
    sc.doc.Views.Redraw()

TestAddTextWithMask()
# For example...
fi = sc.doc.Fonts.FindOrCreate("Times New Roman", true, false);
if (fi >= 0):
    # To do...

TextEntity.MaskOffset gets or sets the offset for the border around text of the rectangle used to draw the mask. This value * TextEntity.TextHeight is the offset on each side of the tight rectangle around the text characters to the mask rectangle. The default value is 0.1.

OK, thanks Dale!

Where is that info available? I didn’t find it in the online SDK help, but maybe I looked in the wrong place…

Cheers, --Mitch

The C++ SDK documents this. I’ve added my comments to the RhinoCommon source so that a future help file update will have this…

Thanks gents, I’ve been away the last day.
Will take a look at this.

Cheers,

Adrian

Thanks again, that has worked a treat.
And providing the opportunity to see a full Python Script right through to completion.

Adrian