How to create single line text object in Python?

Hi,

I’m looking into making a python script where I click on a point and it automatically creates the curves of a number in a single line font. I do this now manually with the “text object” command with options “curves” and “allow single stroke fonts”. And think I have most of it figured out except for creating the text object thing. How do I create a Single stroke font text object in Python? There is “Addtext” and “Addtextdot” but both don’t give the wanted output.

Any help would be appreciated.

Hi siemen,
this old thread might be useful for you:

“allow single stroke fonts” should be “_AllowOpenCurves=_Yes”
hth
Ferry

Cool. I searched but didn’t find that topic. I’ll have a look into it. Thanks!

That worked, nice! Thanks a lot @ferry59

One more question which I hope to get answered in this topic, without having to make a new topic:

I want to create some sort of optional menu when asked for input. So let’s say I ask the user to pick a point, I want to be able to have the option to switch to picking curves instead and python then uses the center point of that curve. Is there a way to implement this option to switch between these different modes? I don’t want to make both possibilities in one function because that might cause confusion when accidentally picking a point on a curve.

Further search tells me I need to have a look at GetOption which I’ll do later. Anybody that happens to have a good example or resource on how to use this?

Hi @siemen,

The first thing you need is to have some single stroke fonts installed on your system. If you don’t have any, you can use this one:

https://wiki.mcneel.com/rhino/engravingfonts

Once you have this installed, you can then create a Rhino.Geometry.TextEntity object and then explode it.

http://developer.rhino3d.com/5/api/RhinoCommonWin/html/M_Rhino_Geometry_TextEntity_Explode.htm

– Dale

Hi @dale,

i am trying to create text for laser engraving programmatically in RH5 and python. If i use the font linked above, then create the TextEntitiy as suggested and explode it i get this after adding the curves to the document:

grafik

Is there anything i can do in V5 to make this work despite of scripting the _TextObject command and using the _AllowOpenCurves option ?

Scripting TextEntity works fine in V6 however i get different locations, in V5 it is added above the XAxis while in V6 it is added below the XAxis, so positioning seems to be another challenge.

_
c.

Hi,
I’m really not the right person to answer scripting questions, but I see I’m assigned here for whatever reason.

I don’t see a way to do that in V5 by exploding text.
You can do it using -TextObject in V5, but maybe

means you don’t want to do it that way.

You can do it by scripting either -Text and -Explode or -TextObject in V6.

Maybe if you tell me more about what you want and what the restrictions are on how you want to do it somebody will be able to help more

Thanks @lowell for your answer. To clarify, i try to write a script which works in V5, V6 and Rhino for mac. It does this::

  1. Display a table with curves and text using single stroke font in a conduit
  2. After user changes some settings, add the table objects to the document

So far, 1 and 2 fails in V5, the single stroke font is the one you posted a while ago named “RhSS”. In V6 i can use a TextEntity and explode it into curves as @Dale suggested. So in V6, point 2 works.

Point 2 (display single stroke font in a conduit) fails in V6 as well. Here is a small example using Rhino.Display.CustomDisplay and Rhino.Display.Text3d:

import Rhino
import scriptcontext
import rhinoscriptsyntax as rs
from System.Drawing import Color

def DoSomething():
    
    t3d = Rhino.Display.Text3d("Hello World")
    t3d.Height = 10
    t3d.FontFace = "RhSS"
    
    conduit = Rhino.Display.CustomDisplay(True)
    conduit.AddText(t3d, Color.Blue)
    scriptcontext.doc.Views.Redraw()
    
    rs.GetString("Press Enter when done")
    conduit.Enabled = False

DoSomething()

If you change the FontFace to “Arial” it works. I’ve tried various fonts, the “RhSS” font and the one by mecsoft named “MecSoft_Font-1”.

Yes, this is the workaround for V5 to add the text to the document. But this does not solve the problem with the conduit. It fails using Rhino.Display.DisplayConduit as well in V6. Here is another example:

import Rhino
import scriptcontext
import rhinoscriptsyntax as rs
from System.Drawing import Color

class CustomConduit(Rhino.Display.DisplayConduit):
    
    def __init__(self):
        self.Text = "Hello World"
        self.Plane = Rhino.Geometry.Plane.WorldXY
        self.FontFace = "RhSS"
        
    def DrawForeground(self, e):
        e.Display.Draw3dText(self.Text, Color.Red, self.Plane, 10, self.FontFace)

def DoSomething():
    conduit = CustomConduit()
    conduit.Enabled = True
    scriptcontext.doc.Views.Redraw()
    rs.GetString("Press Enter when done")
    conduit.Enabled = False

DoSomething()

I will use a different font for now i guess which is not single stroke. But it would be nice if you add a you track item for displaying single stroke fonts in a conduit. It appears to be broken in V6.

_
c.

Clement -
You probably realize nothing is going to change for V5. I just want to make that explicit.

In V6, text drawing functions won’t draw single stroke fonts the way you want. That’s not likely to change.

Steve just told me that in V7, they do draw, but I think that’s not working right either. It will likely be fixed.
I don’t know what’s up with that right now, but it is a goal for V7. That means drawing on the screen, in conduits, and printing.

In order to draw single stroke fonts on the screen in a conduit in V5 or V6 you would have to get the curves and draw those, including calculating the transforms yourself. That would be possible but not fun.

Thanks @lowell. It’s a slight disappointment though, i was in the hope that such things would still be fixable in V6.

I see no way to do this with TextEntity in V5. I can make above work in V6 only. In V5, to get valid curves for the preview conduit, i would have to add the curves to the document first using the regular _TextObject _AllowOpenCurves=Yes command, delete the curves and then show the curves in the conduit. Thats not feasable as there could be a lot of text and the conduit’s purpose was meant to actually avoid adding anything to the document. (In the conduit, i plan to show text as preview as this runs fast, while once added to the doc, the text is converted into curves for laser engraving, which is much slower).

_
c.