Change text dot's text programmatically

Hi, I’m trying to change the text in text dots using the C# component. This is what I have. When I run it, the text dots do not change. Any ideas about what I’m doing wrong?

private void RunScript(bool activate, Guid x, string y, ref object A)
{
if(activate){
Rhino.DocObjects.ObjRef objref = new Rhino.DocObjects.ObjRef(x);
Rhino.Geometry.TextDot dot = objref.TextDot();
string dotText = dot.Text.Substring(1, 2);
dotText = y + dotText;
dot.Text = dotText;
A = dot.Text;
}

Not an expert but it seems that “dot” in a new object because if I add that
RhinoDocument.Objects.Add(dot);
I get a new TextDot.

Laurent, thank you. Any idea how to get to the existing dot to change its .Text property? Maybe using ObjRef is the wrong approach?

Maybe using this: http://developer.rhino3d.com/5/api/RhinoCommon/html/M_Rhino_DocObjects_Tables_ObjectTable_Replace_23.htm

Something that seems to work

Rhino.DocObjects.ObjRef objref = new Rhino.DocObjects.ObjRef(x);
Rhino.DocObjects.TextDotObject dotObject = objref.Object() as Rhino.DocObjects.TextDotObject;
TextDot tdot = dotObject.Geometry as TextDot;
tdot.Text = y+ tdot.Text.Substring(1, 2);
dotObject.CommitChanges();

Based on

See attached as well

TextDot_entryLevel_V1.gh (121.0 KB)