Attribute User Text as Python dictionary

Hello!

I am trying to retrieve all objects from the rhino document in order to get their Attribute User Text as a Python dictionary. No luck so far…

What I have been trying is this:

for rObj in Rhino.RhinoDoc.ActiveDoc.Objects:
print rObj.Attributes.UserDictionary.Values

I get what looks like an empty dictionary - am I approaching this the wrong way?

Best
Frans

You are kind of approaching it in the wrong way. The UserDictionary property is a .NET collection of type ArchivableDictionary. Although this is just a detail, what really matters is to understand that RhinoCommon is built in C#, reason why you will never get a Python object in return. You will need to extract all the necessary data from the ArchivableDictionary object to convert it in to a python dictionary. I am very sure that this has already been done by many other people if you search in StackOverflow.

On the other hand, if values are empty ( simply an empty array) , it just means that the user dictionary has not been assigned any values yet.

1 Like

Hi Frans,

I like to use rhinoscriptsyntax for stuff like this. It’s pretty simple to e.g. iterate over all objects in a Rhino layer (using rs.ObjectsByLayer), and then harvesting their user attribute texts (using rs.GetUserText), and then shoving this into a Python dictionary as you go along.

A minimal (non-)working example file also helps with debugging :wink:

1 Like

Yeah sorry, its just that I don´t really know what I am asking for.
What I want to do in the end is to create a python object instance that contains the geometry and a set of attributes that is derived from the Attribute User Text. But I cant seem to find the right object property (?).boxz.3dm (53.2 KB)

ghPython:

import Rhino

for rObj in Rhino.RhinoDoc.ActiveDoc.Objects:
    print rObj.Attributes.UserDictionary.Values

Here’s a quick example using the functions I mentioned above operating on your test file:


200908_GetRhinoObjectsUserData_GHPython.gh (5.2 KB)

2 Likes

Awesome Anders As Always!
//fr

1 Like