Wrap (2D) Text via Python/Rhinocommon

Hello Everybody,

is there any way to change (2D) text wrapping and the associated “textbox width” by means of Python or Rhinocommon? Especially with the new rich text features in WIP it would be amazing to be able to handle this via script! :innocent:

While we’re at it:
If I do my wrapping “manually” meanwhile, does anyone have a better idea than:

  • Adding all words separately as text to the object table
  • Measuring widths by wrapping bounding boxes around the words
  • Adding \n to the sentence before it overshoots the required length
  • Deleting all single words from the object table
  • Adding the wrapped sentence as text to the object table

Seems possible, but not very elegant :sweat:

Thanks in advance!

1 Like

@lowell, can you maybe help?

I’m not really sure where the sdk completeness is on that but it is supported at some level. Just not sure if it’s exposed very well yet.
You can, or will be able to, set text wrapping on for a text object and set the width of the wrapping box with separate functions.
I’ll try to get a look at it soon

Good to hear that you’re on it!
I managed to solve the problem as described for the time being, but using Rhino native wrap would of course be less hacky.
When you’re at it: Is there any chance to know within Rhinocommon how long a text object will be without adding it to the object table and measuring it. As far as I can see, a TextEntity object has no measurable size, is that right?
Thank you!

Just found RichTextObject and AnnotationText Classes on Rhinocommon API, which include the Properties and Methods I searched for. Unfortunately these seem not to work at the moment as the Rhino Text Object is still based on a V6Annotation.TextEntity class for which I couldn’t find any documentation on the web…
Is the move from V6Annotation to AnnotationText just in the works?
Can we expect these things to work in one of the next WIPs?
Or is ist still a bigger issue and I should stick to Rhino 5 solutions?
(I found the python command rs.TextObjectText always returning None with RH6 Rich Text Objects at the moment… Probably a related bug I guess?)

In the WIP all of the previous annotation classes have been replaced by new ones. The new ones had V6 in their names while both were there side by side and have been renamed now.
We do expect them to work in a future WIP.
I don’t know where the python part of this is. Maybe @Alain can tell you more about that.

Hi, Like Lowell mentions previous annotation classes have been replaced by new ones. The properties and methods you mention should be working in the next WIP or the one right after.

Great to hear! I will try it again then.
Thank you guys for those informations!

I am also interested in customizing text display in this way, and am exploring coding a ‘hacky’ way to divide the text into separate strings stacked atop each other. The end game for me is the automatic creation of tidily formatted anno tags. Any luck on your end?