[python] text edit

How do I find text by uuid and edit it with python?

not TextObject, just Text

texts=[obj for obj in rs.ObjectsByType(512) if rs.IsText(obj)]
will get you the GUIDs of all texts in the document.

Hi Mitch, (@Helvetosaur)

The problem is not getting the ID but taking the ID and editing the string.

Once you have the ID, you can get/set the text object content by using rs.TextObjectText(obj)

I know there is difference between commands _Text and _TextObject,

I am talking about _Text

I don’t see in the api for class TextEntity a way to edit the actual string.

https://developer.rhino3d.com/api/RhinoCommon/html/T_Rhino_Geometry_TextEntity.htm

See this:

import rhinoscriptsyntax as rs
import Rhino
import scriptcontext as sc

obj_id = rs.GetObject("select: ")

key_string = "key"
value_string = "da value"
rs.SetUserText(obj_id,key_string,value_string)

pt = rs.SurfaceAreaCentroid(obj_id)[0]

txt_string = '%<UserText({0},{1})>%'.format(obj_id,key_string)

rs.AddText(txt_string, pt, 100.0, 'Arial', 0, 2|131072)#

I want to make it so, when I next time run the script and there’s additional data, to be appended to the string, instead of creating a new Text.

Please look in the rs Help. rs.TextObjectText() applies to text blocks, not objects created with the Rhino TextObject command - as once those are created, they are not editable text, but curves, surfaces or volumes.

To see what RhinoCommon methods the rs methods are calling behind the scenes, look in the library

C:\Users\<username>\AppData\Roaming\McNeel\Rhinoceros\6.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rhinoscript

In this case, TextObjectText() is in Geometry.py

1 Like

I see, I was confused because of the name of the method.

Thanks.

In general you need to replace the original string with a new string that contains the original text plus the appended text.

1 Like

Yeah, I understand, in rs text blocks are referred to as text objects (programming-speak) and this is easily confused with the TextObject Rhino command.

1 Like