AnsweredAssumed Answered

ExecuteToolAsync not adding resulting layer to map.

Question asked by jawest1 on Aug 2, 2019
Latest reply on Aug 2, 2019 by MBDriscoll

I have created a tool with python that I am running from an add-in using Geoprocessing.ExecuteToolAsync. My code gets the (x,y) center of the current map extent and makes x,y event layer from that point. I then attempt to run arcpy.conversion.LayerToKML tool. What I am finding is that the layer I create never gets added to the map/project even though I have tried specifying "GPExecuteToolFlags.AddOutputsToMap" and "GPExecuteToolFlags.Default ", which both are supposed to add all resulting layers to the map. The LayerToKML tool doesn't work if the layer being used isn't added to the project. I can get the code to run and create the layer that I want and save it using SaveToLayerFile_mangement, but how do I get it to add to the map. I have looked at the documentation extensively and haven't found anything helpful. Also I know the LayerToKML tool works through the ExecuteToolAsync because I can run it by itself (commented out other code and ran on layer added to map after creating with 1st part of script).

 

 

var xE = middlePoint.X.ToString();
var yE = middlePoint.Y.ToString();

var parameters = Geoprocessing.MakeValueArray(xE, yE)
string tool_path = @"PATH\Jwtools.tbx\Script";


var progDlg = new ProgressDialog("Running Geoprocessing Tool", "Cancel", 100, true);
var progSrc = new CancelableProgressorSource(progDlg);
progDlg.Show();
var gp_result =  await Geoprocessing.ExecuteToolAsync(tool_path, parameters, null, new CancelableProgressorSource(progDlg).Progressor, GPExecuteToolFlags.AddOutputsToMap);
Geoprocessing.ShowMessageBox(gp_result.Messages, "GP Messages", gp_result.IsFailed ? GPMessageBoxStyle.Error : GPMessageBoxStyle.Default);
progDlg.Hide();

Outcomes