Persistence of objects/values in scene files


How is scene file persistence of user/plugin objects/values handled in Rhino 6? A code example would be great.



Hi Carsten,

You can user text or user data to pretty much any object in the document. You can also add data just to the document.

Here is a sample to give you an idea what’s possible.

– Dale

Hello Dale,

I got the persistence for our render options working. Now I am wondering how to best persist the viewport options. Do you have a suggestion for how to identify each viewport uniquely, and persist the settings so that they stick with the right viewport?

Hi Carsten,

Viewport have unique ids (UUIDs) that you can use to track them.’

– Dale

Just to be clear, these UUIDs persist across sessions and layout changes?


– Dale

Great, thanks. I am just making the changes now, and hit one minor snag (for which I have a work-around): would you consider adding Guid -> GUID support for MethodGen?

MethodGen already supports UUIDs. Just decorate your “C” functions with ON_UUID.

RH_C_FUNCTION void MyFunction(ON_UUID uuid);

MethodGen will generate this:

internal static extern void MyFunction(Guid uuid);

Does this help?

I don’t find the definition for ON_UUID, nor the Microsoft help page for this type. Where does this come from?

ON_UUID comes from OpenNURBS (the ON is short for that).ON_UUID is pretty much an alias for GUID

I am using Rhino.Collections.ArchivableDictionary to store things in, and using this to persist our settings. Currently, it appears that all set calls fail. Do you have any idea what we might be doing wrong, or might there be an issue in the current version? Our code looks like this:

    private RenderOptions()
        m_dict = new Rhino.Collections.ArchivableDictionary();
        m_dict.Set(IFR_PRODUCTION_RENDERER, Native.Render.GetRenderer(ProdId));
        m_dict.Set(IFR_DESCALE_FACTOR, Native.Render.GetDescaleFactor());
        m_dict.Set(IRAY_MAX_SAMPLES, Native.Render.GetMaxIterations());

The ALLCAPS values are strings. After these calls, the dictionary is empty.

It appears to be because the strings are defined in the class like this:

    private static string IFR_PRODUCTION_RENDERER = "ifr_production_renderer";

It doesn’t work when the strings are static. Apparently there something I need to go read up on there.

Let me know if you need any help with this.

– Dale

Adding readonly to the string constants fixed it. I am not sure why the initialisation order is so whacky without it, but I am looking at other things now. Thanks.