Change text dot's text programmatically

unhandled

#1

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;
}


(Laurent Delrieu) #2

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.


#3

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


(Michael Pryor) #4

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


(Laurent Delrieu) #5

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


(Pfotiad0) #6

See attached as well

TextDot_entryLevel_V1.gh (121.0 KB)