Fonts.FindOrCreate fails to find font

Hi @Pascal and @dale,

i am trying to create a TextEntity using the “Arial Black” font. To locate it, i use:

te.FontIndex = scriptcontext.doc.Fonts.FindOrCreate("Arial_Black", False, False)

Unfortunately the font is never found after Rhino is freshly opened. Only if i run eg. the _TextObject command before, and create something using the Arial Black font, it is then found with my script. If i then open a new file, the font is also found using FindOrCreate. But if i reopen Rhino, the font is not found again.

How to reliably locate the font and use it ? Things i’ve tried allready:

I’ve iterated over System.Drawing.Text.InstalledFontCollection().Families (slow) which lists my required font.Name as “Arial Black”. Unfortunately, this is not the proper Name to use with FindOrCreate, it only can use the font if i put an underscore between the words and do before what i’ve described above.

Do i really need to script the Rhino command as shown here ?

Note: this is R6, i try to find a way to do this reliable in R6 and R7

thank you,
c.

The following script works to create the text with the desired font, but only as curves. Please uncomment below to create the text as polysurfaces, it will crash R6:

import Rhino
import rhinoscriptsyntax as rs
import scriptcontext

def AddText():
    font = Rhino.DocObjects.Font.FromQuartetProperties("Arial Black", False, False)
    te = Rhino.Geometry.TextEntity()
    te.Plane = Rhino.Geometry.Plane.WorldXY
    te.Text = "ABCDEFG"
    te.Justification = Rhino.Geometry.TextJustification.MiddleCenter
    te.TextHeight = 1.0
    te.FontIndex = scriptcontext.doc.Fonts.FindOrCreate(font.QuartetName, False, False)
    
    curves = te.CreateCurves(te.DimensionStyle, False, 1.0, 0.0)
    for crv in curves:
        scriptcontext.doc.Objects.AddCurve(crv)
    
    # below crashes Rhino 6
    # breps = te.CreatePolySurfaces(te.DimensionStyle, 4.0, 1.0, 0.0)
    
    scriptcontext.doc.Views.Redraw()

AddText()

Also, if i use different spacing, eg. 2.0 in this line:

curves = te.CreateCurves(te.DimensionStyle, False, 1.0, 2.0)

the TextJustification.MiddleCenter is not preserved.

_
c.

I am unable to repeat this. Did you submit a crash dump?

I can repeat the spacing/justification issue.

https://mcneel.myjetbrains.com/youtrack/issue/RH-63543

– Dale

Hi @Dale, below is the correct script to repeat the crash. You need to remove the curve creation and just try to create the breps:

import Rhino
import rhinoscriptsyntax as rs
import scriptcontext

def AddText():
    font = Rhino.DocObjects.Font.FromQuartetProperties("Arial Black", False, False)
    te = Rhino.Geometry.TextEntity()
    te.Plane = Rhino.Geometry.Plane.WorldXY
    te.Text = "ABCDEFG"
    te.Justification = Rhino.Geometry.TextJustification.MiddleCenter
    te.TextHeight = 1.0
    te.FontIndex = scriptcontext.doc.Fonts.FindOrCreate(font.QuartetName, False, False)
   
    # below crashes Rhino 6
    breps = te.CreatePolySurfaces(te.DimensionStyle, 4.0, 1.0, 0.0)
    for b in breps:
        scriptcontext.doc.Objects.AddBrep(b)
        
    scriptcontext.doc.Views.Redraw()

AddText()

I’ve just submitted the crash report with the (empty) file.

thanks,
c.

Yeah that works here too:

What email did you submit the crash dump with?

– Dale

None, i just wrote in the Error Reporting dialog that this should be forwarded to you. I have the crashdump and (empty) Rhino file zipped. It is too large (12mb) to upload here, should i upload it to your server instead ?

I am just sending a second crash dump through the Error reporting dialog. I can repeat the crash if i do this:

  1. Run my first script as is
  2. Comment out the code to create the curves
  3. Uncomment the code line to call te.CreatePolySurfaces, you do not have to add the breps to the document
  4. Run code again

_
c.

Yeah, no crashing - sorry.

Do you have another system handy that you can test with?

– Dale

Hi @dale, i am not sure which difference this would make, it crashed here repeatable on the system i have to work with. Did you receive the crash reports and dump files ?

_
c.

Today i’ve tested under V6 and V7 with Windows 10. No crash there.

No, please look closer. Your screen does not show Arial Black, it creates the Text with Arial. Can you show an example where it creates the Text with Arial Black which works right after Rhino has been opened ?

Did you get my crashdump ? (The one i posted here and the two i’ve uploaded ?)

_
c.

See if this sample is helpful:

import Rhino
import scriptcontext

def test_arial_black_text():
    
    text = 'Hello Rhino!'
    plane = Rhino.Geometry.Plane.WorldXY
    height = 2.0
    qname = 'Arial Black'
    qbold = False
    qitalic = False
    
    ds = scriptcontext.doc.DimStyles.Current
    if not ds: return
    ds_bold = ds.Font.Bold
    ds_italic = ds.Font.Italic
    
    te = Rhino.Geometry.TextEntity.Create(text, plane, ds, False, 0, 0)
    if not te: return
    te.TextHeight = height
    
    f = Rhino.DocObjects.Font.FromQuartetProperties(qname, False, False)
    if f:
        te.Font = f
        if qbold != ds_bold:
            if Rhino.DocObjects.Font.FromQuartetProperties(qname, qbold, False):
                te.SetBold(qbold)
        if qitalic != ds_italic:
            if Rhino.DocObjects.Font.FromQuartetProperties(qname, False, qitalic):
               te.SetItalic(qitalic)
           
    scriptcontext.doc.Objects.Add(te)
    scriptcontext.doc.Views.Redraw()
    
if __name__ == "__main__":
    test_arial_black_text()

I looked at the one you posted; it was inconclusive. This is common, which is why I asked for a way to repeat.

– Dale

1 Like

Hi @dale, thank you ! It works. Would be great if this ends in the RhinoCommon docs for reference.

OK, i’ll try to send another if i get any crashes.

_
c.