Select to view content in your preferred language

Change options by SDK

882
4
12-26-2022 11:13 PM
mody_buchbinder
Frequent Contributor

I would like to change  for many people automatically the option to use undo in GP tools by default.

You can see the option I would like to change in the attached screen shot.

Pro SDK have this: https://pro.arcgis.com/en/pro-app/latest/sdk/api-reference/topic73588.html  but it does not have this option.

I could not find anything in registry or user profile that store this option but since Pro "remember" the new value it must be written somewhere.

Any ideas?

Thanks

0 Kudos
4 Replies
CharlesMacleod
Esri Regular Contributor

Mody, we can expose this property to allow for api change at 3.2 3.1

In the meanwhile, u can use something like this to change it programmatically if u must but I dont really recommend it. There are caveats when changing the User.Config programmatically like this:

1. The application can cache properties and their values and I dont know if this is the case with EnableUndo.

2. This code saves the User.Config on disk and this save is not synchronized with the Options dialog or other application code that may be saving the User.Config (which cld lead to a conflict if both try to save at the same time)

 

internal class ToggleGP_EnableUndo : Button {

 private static readonly string GP_EnableUndo = "EnableUndo";

 protected override void OnClick() {
   var enable_undo = GetGPEnableUndoSetting();
   SetGPEnableUndoSetting(!enable_undo);
 }

 private bool GetGPEnableUndoSetting() {
   var config = System.Configuration.ConfigurationManager.OpenExeConfiguration(
   ConfigurationUserLevel.PerUserRoamingAndLocal);
   var group = config.SectionGroups[@"userSettings"] as ConfigurationSectionGroup;
   var gp_Section = group.Sections["ArcGIS.Desktop.Internal.GeoProcessing.Properties.Settings"] as ClientSettingsSection;
   var enableUndoSetting = gp_Section?.Settings.Get(GP_EnableUndo);
   var rawValue = enableUndoSetting?.Value?.ValueXml?.InnerText ?? "False";
   return Boolean.Parse(rawValue);

 }
 private void SetGPEnableUndoSetting(bool enable_undo) {
   var config = System.Configuration.ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal);
   var group = config.SectionGroups[@"userSettings"] as ConfigurationSectionGroup;
   var gp_Section = group.Sections["ArcGIS.Desktop.Internal.GeoProcessing.Properties.Settings"] as ClientSettingsSection;

   var enableUndoSetting = gp_Section.Settings.Get(GP_EnableUndo);
   //null check...
   if (enableUndoSetting == null) {
     //create a new value
     var element = new SettingElement(GP_EnableUndo, SettingsSerializeAs.String);
     var xElement = new XElement(XName.Get("value"));
     XmlDocument doc = new XmlDocument();
     XmlElement valueXml = doc.ReadNode(xElement.CreateReader()) as XmlElement;
     valueXml.InnerText = enable_undo.ToString();
     element.Value.ValueXml = valueXml;
     gp_Section.Settings.Add(element);
   }
   else  {
     //change the value
     XmlDocument doc = new XmlDocument();
     var sr = new StringReader(enableUndoSetting.Value.ValueXml.OuterXml);
     XmlElement valueXml = doc.ReadNode(XmlReader.Create(sr)) as XmlElement;
     valueXml.InnerText = enable_undo.ToString();
     enableUndoSetting.Value.ValueXml = valueXml;
   }
   config.Save();
 }
}

 

 

 

 

0 Kudos
GKmieliauskas
Esri Regular Contributor

Hi,

It is exposed on ArcGIS Pro 3.1 Beta but it does not work as expected. 

            QueuedTask.Run(() =>
            {
                ApplicationOptions.GeoprocessingOptions.SetEnableUndoOn(true);
            });

I have tried to read new value of property and it still has old value.

0 Kudos
CharlesMacleod
Esri Regular Contributor

Thanks Gintautas, This looks like a bug in the Beta. We will fix it for final.

0 Kudos
mody_buchbinder
Frequent Contributor

Hi Charly

Thanks and happy new year.

As you said - this is a big over kill.

I was hopping somebody will explain where it saved in default and I can write some external code to go and change it from outside Pro

 

Thanks

0 Kudos