Is UserDictionary data from CommonObject saved with the file?

I managed to store custom data in Rhino objects UserDictionary of the active document using a Set method of Rhino.Collections.ArchivableDictionary. I can also retrieve the Rhino.Collections.ArchivableDictionary.Values. Data is definitely stored in objects UserDictionary during runtime.

Problem is UserDictionary is empty after saved Rhino file is reopened. Is UserDictionary meant to be saved with the file like UserText? Are there an additional steps to this process or is there an alternative simple approach to the whole issue of saving custom data with document objects in Rhino files?

Hi @spineribjoint1,

Any chance we can get a code sample, we can run here, that repeat this?

– Dale

Hi @dale

Here is a simple code that stores stores key/value:

import rhinoscriptsyntax as rs

guid = rs.GetObject("Select object", preselect=True)

if guid:
    o = rs.coercerhinoobject(guid, True, True)
    o.UserDictionary.Set('Key', 'VALUE')

Simple code that prints stored key/value:

import rhinoscriptsyntax as rs

guid = rs.GetObject("Select object", preselect=True)

if guid:
    o = rs.coercerhinoobject(guid, True, True)
    print o.UserDictionary.TryGetString('Key')

Result before reloading the saved file (if you Set then TryGet during Runtime):
(True, β€˜VALUE’)

Result after reloading the saved file:
(False, β€˜β€™)

Hi @spineribjoint1,

See if this works any better:

import rhinoscriptsyntax as rs
import scriptcontext as sc

def test_set():
    id = rs.GetObject("Select object", preselect=True)
    if id:
        obj = rs.coercerhinoobject(guid, True, True)
        atts = obj.Attributes.Duplicate()
        atts.UserDictionary.Set('Key', 'VALUE')
        sc.doc.Objects.ModifyAttributes(id, atts)

def test_get():
    id = rs.GetObject("Select object", preselect=True)
    if id:
        obj = rs.coercerhinoobject(id, True, True)
        print obj.Attributes.UserDictionary.TryGetString('Key')

– Dale

1 Like

Thank you @dale, Works perfectly.