Changing dot secondary text problem

Hey guys, i tried to change a dot secondary text and dosen’t work , what i m missing?

import rhinoscriptsyntax as rs

textDot = rs.GetObject(“Select textDot”, rs.filter.textdot)
textDot = rs.coercegeometry(textDot)
#print textDot.SecondaryText
textDot.SecondaryText = “Test”

when you coerce the geometry a copy is made
you just need to reference the actual thing in the rhino document

import scriptcontext as sc
import rhinoscriptsyntax as rs

r = rs.GetObject(' pick text dot', rs.filter.textdot)
td = sc.doc.Objects.FindId(r).Geometry #this is what you want
print(td.SecondaryText)
td.SecondaryText = 'bigger'
print(td.SecondaryText)

Thank you @will_wang for explanantion.
Also you re code make a copy of object ,but with replace function will make it correctly

sc.doc.Objects.Replace(r,td)

1 Like

sorry forgot to include this
there must be a CommitChanges method in the end

Hi, I cannot get the text dot secondary text to refresh in the rhino document. I tried the CommittChanges, but I got textdot has no attribute CommittChanges. What did i miss?

Try this:

mport Rhino
import rhinoscriptsyntax as rs
import scriptcontext as sc

def coercetextdot(id, raise_if_missing=False):
    geom = rs.coercegeometry(id, False)
    if isinstance(geom, Rhino.Geometry.TextDot): return geom
    if raise_if_missing: raise ValueError("unable to convert %s into TextDot geometry"%id)
    
def test_text_dot():
    dot_id = rs.GetObject('Select text dot', rs.filter.textdot)
    if not dot_id: return
    dot = coercetextdot(dot_id)
    if dot.SecondaryText: print(dot.SecondaryText)
    dot.SecondaryText = dot.SecondaryText + ' Test'
    sc.doc.Objects.Replace(dot_id, dot)
    sc.doc.Views.Redraw()
    
if __name__ == "__main__":
    test_text_dot()

– Dale

Hi Dale,

You renamed your raise_if variable in one location but not the other… :wink:

Graham

Works fine. TQ.
got "unsupported operand type(s) for +: ‘NoneType’ and ‘str’,
if secondary text is empty.

is the CommitChanges workflow not valid anymore?
would you recommend the Objects.Replace paradigm over CommitChanges?