Getting LayoutUserText fails when not added to document once

The following code fails when the matching text field hasn’t been added to the document once. Even after adding the text field to the document and deleting it afterward, the code still runs fine. How can I add this text field to the document (and delete it afterward), or is there another way around this?

import Rhino
import scriptcontext as sc

def part_of_code():

    pageview = sc.doc.Views.ActiveView
    id = str(pageview.ActiveViewportID)
        page_scale = Rhino.Runtime.TextFields.LayoutUserText(id, "page_scale")
        print "something went wrong"


I see a bug here in the text field functions when called from python. Thanks ill get a YT made up and fix this now.

I wouldn’t recommend using the TextField functions. These are designed with the specific purpose of evaluation inside of an annotation object.

You should be able to achieve the same result with

page_scale = pageview.ActiveViewport.GetUserString("page_scale")

1 Like