简体   繁体   中英

How to store Revit Add-in Settings with Python?

My Revit Add-in reads at some point a text file, that could be located anywhere. In my current implementation, the path to the text file is hardcoded. I'd like to avoid that, so that when I distribute the Add-in to other people, it doesn't simply crash.

Ideally I'd like to give them the ability of specifying their own location for that file on their computer, and that they don't need to re-specify it every time they re-launch the Add-in ! In other words, I'd like to store once and for all this information. And if you close and re-open Revit, the location is still stored somewhere when you re-use the Addin.

This question is actually similar to this one , except that I'd need a solution when developing in Python ( pyRevit ). Any help?

I implemented two other ways to store Revit add-in settings in the HoloLens Escape Path Waypoint JSON Exporter :

  • Store add-in option settings in XML using the .NET System.Configuration.ApplicationSettingsBase class
  • Store add-in option settings in JSON using custom solution and JavaScriptSerializer class

Both solutions are well suited for what you need.

Check them out in the ExportWaypointsJson GitHub repository .

if you're developing you addon in pyRevit, then you can use the pyrevit.script module to get the configuration for that script.

Ask user for the file location ( pyrevit.forms.save_file helps) and then save the file path in the script configuration. pyRevit handles this automatically and saves the information inside its master configuration file at %appdata%/pyRevit

from pyrevit import script
config = script.get_config()
config.filelocation = 'path/to/your/file'
script.save_config()

And then later, read the configuration like this:

from pyrevit import script
config = script.get_config()
print(config.filelocation)
# or to get the config safely
print(config.get_option('filelocation', None)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM