I have some TextEntity and I want to retrieve the text and the bounding box from it.
When I try to parse the text as text.RichText.ToString(); or text.PlainText.ToString(); it gives me a <empty> results.
Hey @csykes,
Thanks for the tip, however it shows an error of : 1. Unable to cast object of type 'System.String' to type 'Rhino.Geometry.TextEntity'. (line: 57)
In the context of of a headless document, you should look for the object in that document and not the RhinoDocument reference we get in the script editor.
Okay, I will try to find the text objects in the file I am working on.
I am referencing the initial file using the dxf import according to Mr.Baer’s example, then I am trying to get the text data within grasshopper for further process.
Now I need to know the exact location - bounding boxes - of each texts within the file.
Thus I am trying to write something like this below (the logic is to make a list and add bounding boxes to it)
using(var doc = Rhino.RhinoDoc.CreateHeadless(null))
{
doc.Import(path);
var bboxList = new System.Collections.Generic.List<GeometryBase>();
foreach(var ro in doc.Objects)
{
if(ro.Geometry is TextEntity)
{
var inputTextEntity = ro.Geometry as TextEntity;
var tfont = "Arial"; //need to be retrieved from original text
var tHeight = 1.5; //need to be retrieved from original text
var tPlane = Plane.WorldXY; //need to be retrieved from original text
var textOutlineCurves = Curve.CreateTextOutlines(inputTextEntity, tfont, tHeight, 0, true, tPlane, 1.0, 0.01);
var bbox = new BoundingBox(textOutlineCurves);
bboxList.Add(textOutlineCurves);
}
}
Print(te.PlainText);
textBbox = bboxList;
}
However, I have encountered many errors shown in below image: