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();

Comments

7 responses to “Storing Revit Add-in Settings”

  1. Dear Jeremy,
    I have a headache problem.
    How can I fast read the dimensions parameters of lofting model,as well as area and volume attributes.
    And if I change the Long or Width parameter,whether the model can follow the change??
    Sorry for my poor English.
    Thanks,
    Ariel

  2. Dear Jeremy,
    I am a beginner of revit secondary development,please exhibitions.
    Thanks,Ariel

  3. Dear Ariel,
    Please go through the standard getting started material. It addresses all these questions:
    http://thebuildingcoder.typepad.com/blog/about-the-author.html#2
    Good luck beginning and continuing, and I hope you can quickly let go of all your headaches!
    Cheers, Jeremy.

  4. Dear Jeremy,
    Thank for your reply,I have just read some sample codes in your blog.Now i have a problem that how can i know the new form of namespace in 2014 instead of 2010,when i compile the codes in 2010,it always has problems and i cannot find the corresponding new form of namespace in 2014.
    Thanks a lot for your help.

  5. Dear Ariel,
    Only one single release of the Revit API included significant namespace reorganisation, for the transition from Revit 2010 to 2011:
    http://thebuildingcoder.typepad.com/blog/2013/02/whats-new-in-the-revit-2011-api.html
    Search in there for “Changes to the Revit API namespaces”.
    Cheers, Jeremy.

  6. HuanTing Avatar
    HuanTing

    Hi, Jeremy,
    Is it possible for a central file to store project-based information within a RVT file? Because the ProjectInfo element is not accessible under the circumstance.

  7. Dear HuanTing,
    Yes, that is definitely possible.
    I would still have expected the ProjectInfo element to be accessible.
    I learned that many companies restrict access to it in workshared environments, to avoid enabling people to update elements that affect absolutely everybody in the team.
    The best way to store add-in data or project information is to isolate it, e.g. by creating your own DataStorage element and using that:
    http://thebuildingcoder.typepad.com/blog/2012/05/devblog-devcamp-element-and-project-wide-data.html#5
    Cheers, Jeremy.

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading