C# Change Text of TextDot

Hi there,
I fear I have to bother you with a very stupid question.
I’ve been trying to change a TextDot’s Text for one evening now and I don’t know how to move on.

Here is a snippet of my code:
Out of a list of RhinoObjects I try to do the following:

foreach (var subitem in Issues)
{
    var TDot = subitem.Id;
    var IssueDot = new ObjRef(Dot).TextDot();
    IssueDot.Text = "XXXXXXXX";
    IssueDot.SecondaryText = "XXXXXXXXXXX";
    
    subitem.CommitChanges();
}

I will have to create the object, representing the Object from Rhino by it’s Id.
If I print the TextDot’s Text, it’s printed and everything’s fine.
I guess the problem is the way I try to change the text, right?

Thanks for the support in advance.

T.

Hi @tobias.stoltmann,

This works in Rhino 6:

protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
  foreach (var rh_object in doc.Objects)
  {
    var text_dot = rh_object.Geometry as TextDot;
    if (null != text_dot)
    {
      var dupe_dot = text_dot.Duplicate() as TextDot;
      dupe_dot.Text = "XXXXXXXX";
      dupe_dot.SecondaryText = "XXXXXXXXXXX";
      doc.Objects.Replace(rh_object.Id, dupe_dot);
    }
  }

  doc.Views.Redraw();

  return Result.Success;
}

– Dale

1 Like

Hi @dale,

yes, perfect.
I investigated that issues this evening and I got the idea that I might have to replace the object, could not figure out how to do that, though. :wink:

But now it perfectly makes sense.
Thanks a lot!

T.

Hi @dale!

I fear it’s not working in my case.
I am getting values from a DGV and wanna compare them to the values in the dots.
The values I write into them right now are simplifyed to make things more abstract.

The thing is you did the code for a command, but I am using a class for that.
But that should not be a problem, right?

 public void UpdateItems(DataGridView IssueList)
        {
            var Issues = GetItemsFromLayers();

            for (int i = 0; i < IssueList.Rows.Count - 1; i++)
            {
                foreach (var subitem in Issues)
                {
                    var text_dot = subitem.Geometry as TextDot;
                    var dupe_dot = text_dot.Duplicate() as TextDot;
                    dupe_dot.Text = "XXXX";
                    dupe_dot.SecondaryText = "XXXXXXX";
                    
                    Rhino.RhinoDoc.ActiveDoc.Objects.Replace(subitem.Id, dupe_dot);

                }
            }   
        }

Cheers

T.

Don’t forget to redraw all viewports when finished.

doc.Views.Redraw();

– Dale

Hi @dale
I did. Just forgot to paste that. The dots are hidden, btw. might that be the problem?

T.

Probably. If the text dots are not hidden, does the code work?

Normally, you cannot modify document objects that are locked or hidden.

– Dale

Hi Dale.
The visibility’s the problem.

Thanks a lot!