Rhino.PlugIns.Settings tutorial?

I’m looking for some guidance on using the PersistentSettings class from a Rhino 6 plugin.

I see the API documentation, but it’s not clear to me how to set this object up with defaults and initiate loading and saving. Like, where do I fill in the initial setting keys and values for the very first run, which will then be changed, saved, and loaded in future runs?

At first I was trying to use the regular old WinForms .NET Properties.Settings.Default class… but soon found that it is not working/supported from the plugin, and that Rhino.PlugIns.PlugIn contains a PersistentSettings class of its own. I’d like to use it :slight_smile:

Well… It looks like it was as simple as checking if the settings were there, and if not adding them programmatically, then updating them, and next time plugin loaded they were there. I guess everything is handled behind the scenes. Worked like a charm, easy peasy :slight_smile:

I’ll leave this open in case there are any other tips anyone wants to add.

How to wipe any PersistentSettings that I added?
Or where are they stored?

I tried using Settings.DeleteItem() to remove them from memory, hoping it would remove them from the saved settings file… but when I reloaded the plugin it was able to find the previously stored keys and their values. I’d like to clear out anything I added and start fresh.

DeleteItem() is correct, you just need to remember to also SaveSettings() once you’re done.

I have a command for RhinoCycles to clear out all settings. I do that as follows:

FWIW, what I do for RhinoCycles is to have always hard-coded defaults that I use as the default value for getting. I have also implemented the reset button for the options page (OnDefaults

Thank you!

You should almost never have to call DeleteItem. Always try to provide a default value when getting a setting. When the setting is set to its default value it will not be saved to disk.

I agree. I just wanted to delete some testing settings I created initially while trying to figure out the PersistentSettings. Thanks!

The test command I wrote for the case where a setting is no longer used, but still may be in a settings file. These will linger unless you actively delete them. Other than that indeed default values it is.