How to output datasets to an open map/contents pane in ArcPro when running geoprocessing tool

2389
15
01-26-2021 03:13 AM
Darius
by
New Contributor II

Hi,

  • I made a python script which is finding min & max values within a specified buffer around specific location and pointing these locations on the map/raster.
  • This is now configured in a Toolbox as a geoprocessing tool for ArcGIS Pro with configurable parameters.
  • While running the tool, it is outputting the clipped raster, table (with min max values) and point feature class with min max values with coordinates to show min/max locations on the map.

How to add table/raster/feature class which are outputted by the tool directly to file geodatabase? Appreciate for any hints 🙂

  • I tired "Add output datasets to an open map" but without success:

Darius_0-1611657892997.png

  • I tried as well adding the extra code in the python script (did not output dataset to Contents pane)

arcpy.management.MakeFeatureLayer('Min_max_points', 'Min_max_points')
arcpy.AddMessage("Min&Max table added to Contents")

All these datasets are outputted to file gedatabase

Darius_1-1611659138092.png

but nothing is added to Contents pane

Darius_2-1611659171495.png

 

0 Kudos
15 Replies
ArthurCallan
New Contributor II

Did you ever find a solution for this? I am having the exact same issue. Running it as a script tool does not add the data to the Contents. However, running my script in ArcPro's Python Window does output data to Contents Pane.

0 Kudos
DanielJager
New Contributor

If you're still working on this, I have found that this works for me. 

arcpy.MakeFeatureLayer_management("SurveyArea_" + date, "Selection_LayerName")[0]
arcpy.SaveToLayerFile_management("Selection_LayerName", "Selection_LayerName.lyrx")
aprx = arcpy.mp.ArcGISProject("CURRENT")
m = aprx.listMaps("Map")[0]
selection = arcpy.mp.LayerFile("Selection_LayerName.lyrx")
m.addLayer(selection, "TOP")[0]

0 Kudos
DanielJager
New Contributor

Any luck? Are you running 2.8?  I am having the same issues, I've tried all sorts of things, running arcpy.mp but that seems like it mostly used in python window not script tool.

0 Kudos
PICAR40
New Contributor

I do have the same problem and the only solution I found is to use a LayerFile to display the dataset, but it is not very fantastic to proceed like this because the .lyrx must exist. But it is a fact that the Content result of the execution of a geoprocessing tool in the Python consol is not the same as if the geoprocessing tool is executed ftom a Python script. Shame on ESRI to not explain this in the documentation.

radius = arcpy.GetParameterAsText(1)

pt = point_geometry.projectAs(spatial_reference_mtm7,"NAD_1983_CSRS_To_WGS_1984_2")

pointGeometryList = []
pointGeometryList.append(pt)
arcpy.CopyFeatures_management(pointGeometryList,r"memory\Point_outil42")

 

#add a cercle (polygon)
arcpy.analysis.Buffer(r"memory\Point_outil42", r"memory\Outil42", radius, "FULL", "ROUND", "NONE", None, "PLANAR")


#adding the contents of the "memory\Outil42" to the Content using a LayerFile
insertLyr = arcpy.mp.LayerFile("Outil42mem.lyrx")
carte.addLayer(insertLyr)

0 Kudos
PICAR40
New Contributor

Also this solution to use a LayerFile creates a problem with exportToPDF() because ArcGIS Pro 2.8.1 freeze after creating the PDF file.

0 Kudos
StefanBrandt
New Contributor III

This topic is already over a year old, but I likewise stumbled upon the same issue.

Has there been a more recent solution to this problem? I'm using a python script in combination with a task element, but since outputs aren't added to the map, some steps in the task don't work properly.

0 Kudos