Struggles with text entity

From time to time, I’m foolish enough to think I can make text entity work. I’ve almost got it this time, but trying to set the font weight and style is holding me up.

I’m writing a C# script component in Grasshopper. I’m good with C# and I know what enums are, but this phrase from the Rhino API reference has me scratching my head and I’m hoping some of you can enlighten me. If I try to use an int value for the weight or style it pukes.

“Weight enum values Avoid casting these values to int. Use ON_Font::WindowsLogfontWeightFromWeight()”

Just use any of the members of the FontWeight enum ( https://developer.rhino3d.com/api/rhinocommon/rhino.docobjects.font.fontweight ) and FontStyle ( https://developer.rhino3d.com/api/rhinocommon/rhino.docobjects.font.fontstyle ) to the Font constructor ( https://developer.rhino3d.com/api/rhinocommon/rhino.docobjects.font/font ). Ignore the suggestion of using a C++ method. The documentation has more of these entries that aren’t very helpful.

I finally got it to work. Even though I had listed Rhino.DocObjects in the usings, I still had to put the full namespace in.

Rhino.DocObjects.Font(font,Rhino.DocObjects.Font.FontWeight.Bold,

    Rhino.DocObjects.Font.FontStyle.Italic,false,false);

myTextEntity-does-work-261602.gh (8.7 KB)

2 Likes

Hi @Joe4,

With GH in Rhino 8, you should be using the Rhino (tab) components

TextExample.gh (10.9 KB)

– Dale

Thanks, Dale, but I’m trying to minimize the clutter. If I can do what I need in one C# script component, that’s all I need. Having to used 3 or 4 components doesn’t make sense to me.