Change or read Geoprocessing Options in Add-Ins

780
5
Jump to solution
02-24-2021 06:17 AM
Eloy
by
New Contributor II

Is there a way to change or at least to read  geoprocessing options such as "Add output dataset to an open map" in  Add-Ins?

I am working with a table in "memory" that is created with a geoprocess and after its creation is added to the TOC in Standalone Tables.

Geoprocessing.ExecuteToolAsync("management.CreateTable", tableParams, null, null, null, GPExecuteToolFlags.AddOutputsToMap);

If the above mentioned geoprocessing option is not checked, the table will not be added to the TOC, making impossible to insert or read rows in the recently created table in “memory”. At least I would like to read the geoprocessing options in the Add-In so I can create the table in the DefaultGeodatabasePath instead of in “memory” when the option is not checked.

I would appreciate any suggestion. Thanks in advance!

0 Kudos
1 Solution

Accepted Solutions
KirkKuykendall1
Occasional Contributor III

End users don't need ProcessMonitor.  Programmers dealing with undocumented software features do though.

Now that you know where the setting is getting saved, you can write code to read it, like this:

protected override void OnClick()
{
    string cfgFile = GetConfigFile();
    if(cfgFile != null)
    {
        var isAddingOutputToMap = GetAddOutputsToMap(cfgFile);
        Debug.Print($"add output to map: {isAddingOutputToMap}");
    }
}
private string GetConfigFile()
{
    var roaming = Environment
                .ExpandEnvironmentVariables("%APPDATA%");

    var esriFolder = System.IO.Path.Combine(roaming, "Esri");
    //config files for older versions may be present too ...
    var cfgFiles = Directory.GetFiles(esriFolder,
        "user.config", SearchOption.AllDirectories);
    var ver = FrameworkApplication.ResourceAssembly
                .GetName().Version.ToString();
    var cfgFile = cfgFiles.Where(f =>
    f.Contains("ArcGISPro.exe") &&
    f.Contains($"{ver}\\user.config")).FirstOrDefault();
    return cfgFile;
}
private bool GetAddOutputsToMap(string cfgFile)
{
    var xdoc = XDocument.Load(cfgFile);
    var gpSettings = xdoc.Element("configuration")
        .Elements("userSettings")
        .Elements("ArcGIS.Desktop.GeoProcessing.Properties.Settings")
        .FirstOrDefault();

    var node = gpSettings.Elements()
        .Where(e => e.Attribute("name").Value == "AddOutputsToMap")
        .FirstOrDefault();
    return node.Element("value").Value.ToUpper() == "TRUE";
}

View solution in original post

0 Kudos
5 Replies
GintautasKmieliauskas
Regular Contributor

Hi,

GPExecuteToolFlags.AddOutputsToMap and GPExecuteToolFlags.Default flags adds outputs to the map.

You can manage all available flags as you want or as you need.

(https://pro.arcgis.com/en/pro-app/latest/sdk/api-reference/#topic9375.html )

More info about "in_memory" workspace problems here:

https://community.esri.com/t5/arcgis-pro-sdk-questions/in-memory-workspace/m-p/787033#M1303 

0 Kudos
KirkKuykendall1
Occasional Contributor III

I started Pro and went to Settings>Options>Geoprocessing.

I downloaded, installed and started SysInternals ProcessMonitor.

I dragged the "Include Process from Window" icon and dropped it onto the Options window.

KirkKuykendall1_0-1614186069171.png

 

I added two Filters to process Monitor:

KirkKuykendall1_2-1614185687991.png

I unchecked the "add outputs to open map" option, and clicked save.

KirkKuykendall1_3-1614185730160.png

ProcessMonitor shows Pro is writing to :

C:\Users\kirkk\AppData\Roaming\Esri\ArcGISPro.exe_StrongName_yhpsrysqpn4fvmb0spwbakt5o5e50din\2.7.0.0\user.config

I open the file in notepad and see xml setting for AddOutputsToMap set to false.

KirkKuykendall1_0-1614185178060.png

 

 

Eloy
by
New Contributor II

Thank you very much!. You gave me a good hint. Unfortunately I can not expect that the users of the  Add-In will install SysInternal ProcessMonitor. But at least thanks to you I know where is the config information stored

0 Kudos
KirkKuykendall1
Occasional Contributor III

End users don't need ProcessMonitor.  Programmers dealing with undocumented software features do though.

Now that you know where the setting is getting saved, you can write code to read it, like this:

protected override void OnClick()
{
    string cfgFile = GetConfigFile();
    if(cfgFile != null)
    {
        var isAddingOutputToMap = GetAddOutputsToMap(cfgFile);
        Debug.Print($"add output to map: {isAddingOutputToMap}");
    }
}
private string GetConfigFile()
{
    var roaming = Environment
                .ExpandEnvironmentVariables("%APPDATA%");

    var esriFolder = System.IO.Path.Combine(roaming, "Esri");
    //config files for older versions may be present too ...
    var cfgFiles = Directory.GetFiles(esriFolder,
        "user.config", SearchOption.AllDirectories);
    var ver = FrameworkApplication.ResourceAssembly
                .GetName().Version.ToString();
    var cfgFile = cfgFiles.Where(f =>
    f.Contains("ArcGISPro.exe") &&
    f.Contains($"{ver}\\user.config")).FirstOrDefault();
    return cfgFile;
}
private bool GetAddOutputsToMap(string cfgFile)
{
    var xdoc = XDocument.Load(cfgFile);
    var gpSettings = xdoc.Element("configuration")
        .Elements("userSettings")
        .Elements("ArcGIS.Desktop.GeoProcessing.Properties.Settings")
        .FirstOrDefault();

    var node = gpSettings.Elements()
        .Where(e => e.Attribute("name").Value == "AddOutputsToMap")
        .FirstOrDefault();
    return node.Element("value").Value.ToUpper() == "TRUE";
}
0 Kudos
Eloy
by
New Contributor II

Thank your very much!

0 Kudos