Update dimension text after creation

Hi All,

I want to add a label to some diemnsions much like you would do manually via the properties dialog. e.g text value is “<> LABEL”.

In Python, I have the dimension object (or GUID if that helps), and I can edit the RichText, TextFormula or PlainText properties, but they don’t have any effect.

Are these the right properties, or is there a commit change method (or some other solution) I’m missing?

Thanks

Hope this helps:

import Rhino
import scriptcontext as sc

def EditLeader():
    filter = Rhino.DocObjects.ObjectType.Annotation
    rc, objref = Rhino.Input.RhinoGet.GetOneObject("Select leader to edit", False, filter)
    if not objref or rc!=Rhino.Commands.Result.Success: return rc
    obj = objref.Object()
    if type(obj) is not Rhino.DocObjects.LeaderObject:
        return Rhino.Commands.Result.Failure
    txt = ''
    rc, txt = Rhino.Input.RhinoGet.GetString("New text", False, txt)
    if rc!=Rhino.Commands.Result.Success: return rc
    leader = obj.LeaderGeometry
    leader.SetRichText(txt, leader.DimensionStyle)
    obj.CommitChanges()
if __name__=="__main__":
    EditLeader()

Thanks for the reply.

I tried the following:

dim.Geometry.SetRichText("<> LABEL",Doc.DimStyles.FindName("_StyleName"))

It didn’t error, but it didn’t have any effect either. Is that what you were suggesting?

Afterwards, add this line of code:

dim.CommitChanges()

Here is the complete code for changing the text of a linear dimension:

import Rhino
import scriptcontext as sc

def EditLinDim():
    filter = Rhino.DocObjects.ObjectType.Annotation
    rc, objref = Rhino.Input.RhinoGet.GetOneObject("Select Linear Dimension to edit", False, filter)
    if not objref or rc != Rhino.Commands.Result.Success: return rc
    obj = objref.Object()
    if type(obj) is not Rhino.DocObjects.LinearDimensionObject:
        return Rhino.Commands.Result.Failure
    txt = ''
    rc, txt = Rhino.Input.RhinoGet.GetString("New text", False, txt)
    if rc != Rhino.Commands.Result.Success: return rc
    obj.Geometry.SetRichText(txt, obj.Geometry.DimensionStyle)
    obj.CommitChanges()
if __name__ == "__main__":
    EditLinDim()

1 Like

Thanks - I knew it would be something simple like that.