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!
Solved! Go to Solution.
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";
}
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
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.
I added two Filters to process Monitor:
I unchecked the "add outputs to open map" option, and clicked save.
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.
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
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";
}
Thank your very much!