Read TextEntity headless

Hello,

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.

What would be the best way to read the TextEntity inside gh?

parseTextEntityHeadless.gh (3.8 KB)

Thanks in advance.
Amaraa~

Hey @amaraa, you’d need to cast your input, currently you’re creating a new empty TextEntity and printing that.

// Replace
TextEntity htext = new TextEntity();
// With this
TextEntity htext = (TextEntity)x;

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)

I’ve tried all type hint of the ‘x’ input but it’s still the same.

Have you tired it on your pc?

How are you referencing the text entity?

You should first find the RhinoObject in the document, then get its geometry as a TextEntity:

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.

1 Like

Hello,

These texts are referenced as .dxf files in headless environment.

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.

1 Like

Ok. So in your case, you need to loop through the objects in the doc you create and check if the object geometry is a TextEntity. Something like:

2 Likes

Thank you very much Mr.Luis for your fast response, it works very well.

I will work on the bounding box of these words now,
Have a great day ahead.

Greatly appreciated,
Amaraa

1 Like