How to clear custom project settings?

832
2
Jump to solution
02-16-2021 06:39 AM
DanielRoth
Esri Contributor

Hi everyone

How can I clear custom project settings? No matter whether I set the value to null

settings[""] = null;

 or set the settings object to null

settings = null;

it keeps returning. Does it live forever in the .aprx? Like a zombie 😉 

Thank you and regards,

daniel

0 Kudos
1 Solution

Accepted Solutions
Wolf
by Esri Regular Contributor
Esri Regular Contributor

If you are talking about 'custom project settings' then your findings are correct.   The API exposes only two overrides in the Module class that allow to read/write the project settings: OnReadSettingsAsync and OnWriteSettingsAsync.  And you are correct since once you create those settings initially and save the project file your settings stick around for good.   OnWriteSettingsAsync only allows you to replace an existing setting and doesn't allow you to delete any existing settings from the key/value pair list of project settings.  As a workaround I would suggest to add a boolean setting named something like "UseDefaults" and set that to true in order to clear any existing settings.  Once you read settings, check for "UseDefaults" and if its value is true just ignore all other existing settings.

View solution in original post

0 Kudos
2 Replies
Wolf
by Esri Regular Contributor
Esri Regular Contributor

If you are talking about 'custom project settings' then your findings are correct.   The API exposes only two overrides in the Module class that allow to read/write the project settings: OnReadSettingsAsync and OnWriteSettingsAsync.  And you are correct since once you create those settings initially and save the project file your settings stick around for good.   OnWriteSettingsAsync only allows you to replace an existing setting and doesn't allow you to delete any existing settings from the key/value pair list of project settings.  As a workaround I would suggest to add a boolean setting named something like "UseDefaults" and set that to true in order to clear any existing settings.  Once you read settings, check for "UseDefaults" and if its value is true just ignore all other existing settings.

0 Kudos
DanielRoth
Esri Contributor

Thanks for the clarification, Wolfgang

0 Kudos