File3dmobject attributes

Hi,
I am trying to get Keys and Values from an external 3dm file by python code.

I am able to get the Keys but not the Values in a list. When I create another python component and get the file3dmobjects as an output into new component then it seems to work (able to get values)…

Here is my code:

import Rhino as r
f=r.FileIO.File3dm.Read(x)
o=f.Objects
values =
a=[i.Attributes.GetUserStrings().AllKeys for i in o]

for key,objs in zip(a,o):
v= objs.Attributes.GetUserStrings().Get(key)[0]
values.append(v)
b=values

Thanks in advance…

can you attach the 3dm file you are trying to read?

also you can format the code using codeblocks

    import Rhino as r
    f=r.FileIO.File3dm.Read(x)
    o=f.Objects
    values = []
    a=[i.Attributes.GetUserStrings().AllKeys for i in o]

    for key,objs in zip(a,o):
    v= objs.Attributes.GetUserStrings().Get(key)[0]
    values.append(v)
    b=values

Hi José,

Thanks for info about codeblock. I am working on a really simple file as you can see at the attachment, trying to succeed with this then try more complex ones later on… I cannot figure out where is the mistake because if I write the code as f.Objects.Attributes I do not get any attributes since it is ObjectTable, but [i.Attributes.GetUserStrings() for i in o] I get results as NameValueCollection, after that it seems I am not able to get the values of those NameValueCollection, unless I connect the output of that into another python component…

Thanks…
Panels.3dm (849.1 KB)

When you stored the keys you got an array with all the user strings. Then when you where passing that array as a key and that was generating the error. You just need to slice the array before passing it as a key, in your code:

a=[i.Attributes.GetUserStrings().AllKeys[0] for i in o]

I hope this helps

20201103_getuserstrings.gh (5.7 KB)

Hi José,

Yes this helps, however my real issue is to get all keys and values and if there are different amount of keys&values for each object…
Panel 1 could have some more info 3 keys and 3 values but Panel 2 could have only 1 key and 1 value…
This issue I could not figure out actually…

Thanks a lot.

Then you just need a second for loop to get all the keys for each object. Here the attributes are stored a a nested list and a nested dictionary.
I guess you’ll need some sort of id to access the objects properly instead the object index I’m using to build the dictionary

20201103_getuserstrings.gh (7.9 KB)

Hi José,

This helped a lot. Now I will keep looking into bind this together with the geometry. Thank you very much.