How to check what .keys exist on Document User Text?

Hi,

I am setting document user text via python using a runpythonscript command
sc.doc.Strings.SetString(key, str(value))

But after running a few such commands, how do I check what .keys exist in the Document? As usual .keys are not exposed on the UI.

There is no way to plug a document into grasshopper’s user text component (which is what I usually use to see the .keys on model objects). The field expressions component only gives values for keys, it would be nice if I can also retrieve a list of all keys on the Document User Text.

Could you please give it a try with Query Model Objects + User Text ?

Hi Jessesn, I am asking regarding User Attribute Text on the Document and not User Attribute Text on Model Objects. Are you saying that there is a way to connect the Document to the User Text component?

In Rhino run _ScriptEditor, add a new Python 3 script and paste this code:

#! python 3

import scriptcontext as sc

for i in range(sc.doc.Strings.DocumentUserTextCount):
    print(sc.doc.Strings.GetKey(i), ":", sc.doc.Strings.GetValue(i))

This will print all keys and their values to the command-line and script editor terminal, including keys starting with a ..

2 Likes

Thanks Nathan! Works like a charm :grin: