Select to view content in your preferred language

python addin: best practise for persisting custom setting?

2068
3
01-22-2014 06:19 AM
Laurensvan_der_Burgt
Deactivated User
Dear,

For the development of a Python addin (extension) for ArcMap I would like to manage a user setting which persists over multiple arcMap sessions.

I have been exploring several options with an xml settings file.
One of the things I found out that it is not possible to directly use a file included in the plugin's Install folder: the contents of this folder are overwritten in the Addin AssemblyCache folder so the original state of the settingsfile is reverted for each new ArcMap session.

I managed to find a solution by copying the settingsfile to a general accessible location and check for existence each time the extension loads. However, this is a rather devious solution. Any other ideas of how to accomplish this?

Cheers, Laurens
Tags (2)
0 Kudos
3 Replies
markdenil
Frequent Contributor
Devious, perhaps, but writing to some location in the user's personal directory is the usual way of doing it.
For example, Arc places the default geodatabase and workspace there.
0 Kudos
Luke_Pinner
MVP Regular Contributor
Write it to %APPDATA%\your_adddin_name\your_config_file.xml.

This way, it gets written to a users profile and will not get overwritten by later users (who will get their own config file).

e.g.
import os
config=os.path.join(os.environ['APPDATA'],'your_addin_name', 'your_config_file.xml')
0 Kudos
Laurensvan_der_Burgt
Deactivated User
Thanks for the quick responses!
Indeed useful to ensure that each user will gets a separate instance of the config file.
0 Kudos