Get/modifiy UserText from Rhinocommon in Python

Hi everybody,

I’m stuck on a little problem: I want to read/modify UserText data of objects from Rhinocommon, but for the moment all my attempts stayed ineffective…

I tried to access to the UserDictionary of the object, but it doesn’t return me anything… In fact, I’m not sure to get the difference between UserData, UserDataList and UserDictionary.

Could someone have the kindness to explain how work these objects and maybe write a short example showing how to read/modify UserTest via Rhinocommon?

Many thanks!

OK, I found the answer: have to use GeometryBase.SetUserString and .GetUserString methods.

But if someone still could explain me the goal/difference of UserData and UserDictionary, it would be though usefull!

UserString is the most simple way to attach data to an object: you can only store strings.
Next up is the UserDictionary, in which you can store key-value pairs. The keys are always strings, but the values can be may different types, including other dictionaries.
The most complex way to attach data is to use a custom UserData class, which needs to be able to read and write itself to file. With this, you can do anything that is serializable.

Each of them caters to specific use cases. Don’t use the more complex way to achieve something simple is what I would say. Personally, I always use the UserDictionary and have never had the need for the more complex UserData.

4 Likes

Hi menno,

Many thanks for these explanations!

Hi,
I am new to rhino development and I was searching for “how can I remove some UserString that I have attached to the object”. can you help me with that, please?

Maybe this topic helps

Thank you Menno.
It worked :slight_smile:
all I had to do was to set the value of that key to null!

1 Like