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);
}
Any suggestions? It would be greatly appreciated.
Thanks in advance!
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;
}
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
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);