Textbox with fields is not updating after TextObjectText is called


#1

Hello,
I’m trying to update some text with the correct page number using python. I want to use the field %< pagenumber>% but the resulting text is printed out as %< pagenumber>% instead of the correct page number (1, 2, 3 ect).

textRep = rs.TextObjectText(id, currentText+'%<pagenumber>%-'+key)
Returns=>
“VIEW %< pagenumber>%-3A”
(I had to add the pace after the first carrot so that it would print in this forum, but the space isn’t there in the code)

How do I get the text to refresh and print the correct output? if I click on the text and then hit escape the text will update and display the page number correctly.

Thanks
Ian


#2

@NavArch,

seems like AnnotationBase.Text does not automatically interpret AnnotationBase.TextFormula, but it works the other way around, if you include your text with TextFormula:

import Rhino
import scriptcontext
import rhinoscriptsyntax as rs

def DoSomething():
    
    id = rs.GetObject("Select text object", 512, True, False)
    if not id: return
    
    currentText = rs.TextObjectText(id)
    key = "3A"
    
    te = rs.coercerhinoobject(id, True, True)
    te.Geometry.TextFormula = currentText + "%<pagenumber>%-" + key
    te.CommitChanges()
    
    scriptcontext.doc.Views.Redraw()
    
DoSomething()

Note that i do not check anything in above example. Your text should be on a layout page for this to work and the old textobject text should not contain a formula yet.

c.


#3

Thanks Clement,
That did the trick. Turns out it works even if there is a formula in the text already too.

Ian