AddTextObject?


#1

I’m trying to generate some curves using text data. While there is rs.AddText for Text, there isn’t a rs.AddTextObject for the TextObject equivalent. What do I do?

Edit: I found http://wiki.mcneel.com/developer/scriptsamples/converttexttogeometry which does have a RhinoScript solution, but that is shockingly dirty.

I’d like a Python solution if possible.


How to create single line text object in Python?
#2

You will need to program rs.Command() with _TextObject in this case. Following is a quickie example…

import rhinoscriptsyntax as rs

def AddTextObjectAsCurves():
    tol=rs.UnitAbsoluteTolerance()
    text=rs.GetString("Enter your text")
    if text==None: return
    
    ht=rs.GetReal("Text height?",minimum=tol)
    if ht==None: return
    
    commStr="-_TextObject _GroupOutput=_Yes _FontName=Arial "
    commStr+="_Italic=_No _Bold=_No "+str(ht)+" _Output=_Curves "
    commStr+="_AllowOpenCurves=_No _LowerCaseAsSmallCaps=_No "
    commStr+="_AddSpacing=_No "+text
    
    rs.Command(commStr,True)
    
AddTextObjectAsCurves()

--Mitch

3D Text in Rhino for Mac via Python?
#3

Here is an example using a pre-existing 3D point as the insertion point:

import rhinoscriptsyntax as rs
import Rhino

def AddTextObjectAsCurves():
    tol=rs.UnitAbsoluteTolerance()
    text=rs.GetString("Enter your text")
    if text==None: return
    
    ht=rs.GetReal("Text height?",minimum=tol)
    if ht==None: return
    
    #insertion point, example
    insPt=Rhino.Geometry.Point3d(0,0,0)
    
    commStr="-_TextObject _GroupOutput=_Yes _FontName=Arial "
    commStr+="_Italic=_No _Bold=_No "+str(ht)+" _Output=_Curves "
    commStr+="_AllowOpenCurves=_No _LowerCaseAsSmallCaps=_No "
    commStr+="_AddSpacing=_No "+text+" "+str(insPt)
    
    rs.Command(commStr,False)
    
AddTextObjectAsCurves()

#4

Thanks, I’ll give that a try. What is the function UnitAbsoluteTolerance() for? I don’t see why we have a minimum font size.


#5

Well, you can’t (shouldn’t) have a 0 font height… And in general you shouldn’t be adding elements to the file that are smaller than the absolute tolerance. So I just use this as a quick way to make sure the user enters some positive, valid font size.

–Mitch