Replacing existing text through python script?

Hey there,

so my problem is that I have an existing text in my rhino document (Bauherr: Max Mustermann), that I want to replace through grasshopper via cvs. file that has the actual name, that I want to change.

I already wrote a script that finds the new name from the .cvs file and should change the existing name (Max Mustermann) with the name from the .cvs.
Going through a lot of debugging, rhino is still not able to find the ‘Text’ in my document, even though it’s the only object in the whole project:

‘Runtime error (MissingMemberException): ‘CustomTable’ object has no attribute ‘GetObjectList’’

Is there any way to get Rhino to find my text-properties via script or component ?

thank you in advance!

import scriptcontext as sc
import Rhino
import rhinoscriptsyntax as rs


if new_text is None:
    new_text = "Bauherr: Feathers McGraw"

def set_text(to: str) -> None:
    # https://developer.rhino3d.com/api/RhinoScriptSyntax/#selection-ObjectsByType
    guids = rs.ObjectsByType(0) 
    for guid in guids:
        # obj = sc.doc.Objects.Find(guid)
        geom = sc.doc.Objects.FindGeometry(guid)
        if geom.__class__ not in [Rhino.Geometry.TextEntity]:
            continue
        rs.TextObjectText(guid,to)


try:
    sc.doc = Rhino.RhinoDoc.ActiveDoc
    set_text(new_text)
except BaseException as e:
    raise e
finally:
    sc.doc = ghdoc

Thank you very much! That helped me and the script was running with one value changing through the script.

Since I added a few more values into the .csv and the script, that should be changed, i immediately got the same error again:

Runtime error (MissingMemberException): ‘CustomTable’ object has no attribute ‘GetObjectList’

Traceback:
line 1008, in ObjectsByType, “/Applications/Rhino 7.app/Contents/Frameworks/RhCore.framework/Versions/Current/Resources/ManagedPlugIns/RhinoDLR_Python.rhp/RssLib/rhinoscript/selection.py”
line 53, in set_text, “”
line 73, in ersetze_text_in_rhino, “”
line 79, in script

Even though the Text-Objects that should be changed have the same type, rhino is not valuing them as such.
I already tried the ‘guids = rs.ObjectsByType(0)’ to prevent that from happening, but I still can’t figure out how rhino is not detecting/changing the values/texts, even though they should be type 512 anyway ?

im loosing my mind over this haha, pls send help :smiley:

You’re welcome Maurice.

Can you attach a .3dm file and a .gh file showing the problem?