I am trying to create a TextObject in Rhino6 programaticaly. The problem I encountered is that if the string I use contains a newline, Rhino thinks it is the end of the command and doesn’t give the expected result. Here is the script I use:
The new line (\n) between man_date and patient_name causes the problem. Is there another way to insert a newline in the TextObject without it interpreting it as the end of the command?
Hi Tal, I do not think there is a way, using the-TextObject command - I guess you need to create text in the script, explode to get curves, extrude… or be clever about making the lines yourself in the script with multiple calls to -TextObject…
Yep, that’s what I had to do in my scripts that create multiline text objects… Figure out the text height and line spacing and then offset the insertion points up or down for each line… It gets complicated, my convert text blocks to single stroke text objects (for engraving) is over 100 lines of code, and that’s where the fonts are hard coded (thus tested and measured).
Hi Nathan - Addtext() makes text - as text - the user needs to make text-shaped curves or solids,
= the TextObject command in Rhino (not Text… confusion wins!)
-TextObject is possibly easier, but I just had to try. Comment and uncomment the corresponding lines to get curves or polysurfaces out of the text. And you’ll probably want to play more with dimstyles to use the fonts wanted etc.
import scriptcontext as sc
import Rhino.DocObjects as rdo
import Rhino.Geometry as rg
sometext = "".join(["useful text with number: "+str(i)+"\n" for i in range(0,3)])
ds = sc.doc.DimStyles.CurrentDimensionStyle
oa = rdo.ObjectAttributes()
te = rg.TextEntity()
te.Text = sometext
#texts = te.CreateCurves(ds, False, 1.0, 0.7)
texts = te.CreateExtrusions(ds, 1.0, 1.0, 0.7)
#texts = te.CreatePolySurfaces(ds, 1.0, 1.0, 0.7)
#addedobs = [sc.doc.Objects.AddCurve(text, oa) for text in texts]
addedobs = [sc.doc.Objects.AddExtrusion(text, oa) for text in texts]
#addedobs = [sc.doc.Objects.AddBrep(text, oa) for text in texts]
for obuid in addedobs: sc.doc.Objects.Select(obuid, True)
sc.doc.Views.Redraw()
Yeah, I started down that road but kept getting a crash if I set a break point to look at what was in ‘te’. Do you get that crash? Set a breakpoint someplace and expand the ‘te’ variable - here I get a boom every time. (reported)
You can, however if you need single-stroke text, this approach does not work - as plain Text does not support single-stroke fonts. Well, actually it does, but the display is wrong. However once exploded it does seem to look correct.