Storing Revit Add-in Settings

Here is another tip from the Revit API discussion forum that seems worthwhile cleaning up and making easy to find, on how to store plugin preferences, raised and discussed by Dimi, peterjegan and ollikat:

Question: I am trying to find a way to store user preferences for my plugin.

These preferences are file paths, import options etc. so that the next time the user runs the plugin, all the choices he made the fist time he used the plugin stay the same.

Are there any guidelines how to achieve this, or API functionality that helps?

Answer: If the settings you wish to store are Revit project specific, you can save them in the RVT document in Extensible Storage via the Revit API. This would fit a scenario where a user wants to have different settings in different projects. Here are some more extensible storage topics.

If your settings contain general add-in related information that has no direct relationship with the Revit project, it might be better to use the dedicated Visual Studio C# feature made exactly for this purpose: Using settings in C#.

This is very easy and effective system for storing add-in data.

Some people who want more control develop their own system, but I suggest starting here.

Response: The C# Visual Studio User Settings system suggested above worked fine.

Nevertheless, in my case, it's even easier, since I am storing user settings for Windows Forms entries.

You can easily associate user settings with Windows Form components inside the Form Designer: How to: Create Application Settings Using the Designer.

This means even less code for reading and writing.

The only caveat I found is that you have to call save before closing the form, otherwise the settings will be lost:

  Properties.Settings.Default.Save();