Text Outline C# Script for Grasshopper not working in Rhino Compute

Hello,

I have begun experimenting with Rhino Compute and Grasshopper and let me just say what an amazing thing it is.

I have run into a weird problem that I cannot get around. I have a simple custom C# component in my Grasshopper definition to create text outlines that I use later to engrave text in a mesh. However, it seems like the component is not running when I run the definition in Rhino Compute. I have tried to debug sending the resulting curves to the browser and inspecting the results, but Compute always returns an empty output. The rest of the definition and outputs work well, and Compute does not generate any errors, which is even weirder. I attach the code of my custom C# script:

private void RunScript(double Text, ref object A, ref object B)
{
TextEntity text = new TextEntity();
text.RichText = Text.ToString();
text.TextHeight = 8;
A = text.Explode();
B = text.GetBoundingBox(false);
}

image

Any suggestions? It would be greatly appreciated.
Thanks in advance!

Hi @crazy.crazymon,

Just curious, does this work?

private void RunScript(double x, ref object A, ref object B)
{
  var text = x.ToString();
  var font = "Arial";
  var curves = Curve.CreateTextOutlines(text, font, 8.0, 0, true, Plane.WorldXY, 1.0, 0.01);
  var bbox = new BoundingBox();
  foreach (var c in curves)
    bbox.Union(c.GetBoundingBox(false));
  A = curves;
  B = bbox;
}

– Dale

3 Likes

Hi @dale ,
This works perfect! Thank you so much. Would you mind explaining to me why this method works while the other doesn’t? I would love to understand the reason behind it.
Thanks for the help.
-Samuel

Hi @crazy.crazymon,

Any time you work with a TextEntity, you also need a DimensionStyle would would be in some document.

– Dale

2 Likes

Hi @dale

I’m facing the same problem. In my case, I’d like to use TextEntityso I can call CreatePolySurfaces.
I’ve tried creating the DimensionStyle in code to solve the issue but it doesn’t work either.

Rhino.DocObjects.DimensionStyle dimStyle = new Rhino.DocObjects.DimensionStyle();
dimStyle.TextHeight = 8;
    
Rhino.Geometry.TextEntity text = Rhino.Geometry.TextEntity.Create("example text", Plane.WorldXY, dimStyle, true, 100, 0);

A = text.CreatePolySurfaces(dimStyle, 3, 1, 0);

Any idea on how to solve this?
Thanks in advance!

Hey @pegiachini,

If the method I pointed out (above) work, then just extrude the returned curves and cap into solids if needed.

– Dale

1 Like

@dale thanks for the quick reply,

I thought about that, but the Cap solution doesn’t handle letters with inner holes (i:e a, e, o,…) correctly. Am I missing something?

Best,
Pedro

Use Brep.CreatePlanarBreps to create the planar faces. Then use Brep.CreateExtrusion to extrude the face.

– Dale

1 Like

Worked just fine. Thank you!

This function should work with compute in 7.11 which we will start having release candidates for beginning on Sept 14.

Nice to hear! Thanks!