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

01-26-2021 03:13 AM
New Contributor II


  • 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:


  • I tried as well adding the extra code in the python script (did not output dataset to Contents pane)'Min_max_points', 'Min_max_points')
arcpy.AddMessage("Min&Max table added to Contents")

All these datasets are outputted to file gedatabase


but nothing is added to Contents pane



0 Kudos
14 Replies
MVP Esteemed Contributor

Make Feature Layer (Data Management)—ArcGIS Pro | Documentation

The layer that is created by the tool is temporary and will not persist after the session ends unless the layer is saved to disk or the map document is saved.

You don't indicate whether you are using

  • the python window within Pro, or
  • a separate python IDE or
  • whether Pro is open or or closed

when you run the script

... sort of retired...
0 Kudos
New Contributor II

Hi Dan, thanks for prompt reply.

I am running the tool directly from the Toolbox with ArcPro open



When I am running the code snippet directly from Python window 


I am getting the result and the dataset (which was saved to file geodatabase on previous tool executions) is added to the Contents window


Any thought about why is it not working when it is executed directly from Toolbox/Geoprocessing?

0 Kudos
MVP Esteemed Contributor

try copy features if you have the add to display environment property set properly

... sort of retired...
0 Kudos
New Contributor II

Hello again, not sure here, could you please explain again? Thank you!

0 Kudos
MVP Esteemed Contributor

makefeaturelayer is temporary, it goes away unless it is saved.  I just want to see whether copying it to a gdb adds the results to the display

... sort of retired...
0 Kudos
New Contributor II

Thanks, I tested and copy is behaving exactly the same way when executing command from python window in ArcPro, the dataset is saved to geodatabase and added to Contents pane

arcpy.CopyFeatures_management("Min_max_points", "Min_max_points_copy3")


When adding following code to the end of my script:

# Test for copyig features
arcpy.CopyFeatures_management("Min_max_points", "Min_max_points_copy3")
arcpy.AddMessage("Copy dataset")


the dataset is saved in geodatabase but nothing is added to the Contents pane.


Both commands:'Min_max_points', 'Min_max_points_copy3')

arcpy.CopyFeatures_management("Min_max_points", "Min_max_points_copy3")


are behaving exactly the same way - saving output dataset to geodatabase but not adding dataset to Contents pane when the code is executed from the Tool/geoprocessing.

If you have any more ideas please let me know :)

0 Kudos
MVP Esteemed Contributor

Hmmm no, it works for me and I am not sure what it is about your setup.

I work only with locally stored data and I have full administrative permissions.  Here is my Project, Options, Geoprocessing parameters, which you indicate is the same, but you never know


... sort of retired...
0 Kudos
New Contributor II

Actually I did not have the "Display disabled parameters" thick ON but anyway I tried with this feature ON and it did not helped. Here are my parameters


So I started from scratch, creating new ArcPro project, creating new geodatabase, addin rasters to geodatabase and even adding the script to the toolbox again and configuring parameters. I tried running geoprocessing from my local PC as well remote Citrix server to see if any ArcPro installation or server/pc could have anything related to the issue. No success, no dataset are outputted to Contents pane.


I couldn't find anything related under Environments as well


Here are my tool parameters


Here is tool code

# Import arcpy
import arcpy

# Set geoprocessing environment

# Set variables
Well_Location_SDE = arcpy.GetParameterAsText(0)
SQL_Expression = arcpy.GetParameterAsText(1)
Well_Location_FGDB = arcpy.GetParameterAsText(2)
Radius_Buffer = arcpy.GetParameterAsText(3)
Input_Raster = arcpy.GetParameterAsText(4)
Output_Raster = arcpy.GetParameterAsText(5)
Output_Excel = arcpy.GetParameterAsText(6)
Output_RasterToPoint = arcpy.GetParameterAsText(7)

#arcpy.env.workspace = Output_FGDB

#arcpy.env.overwriteOutput = True
arcpy.AddMessage("Variables set")

# Applying SQL expression
# Remeber to not mix input and outup here that is why we use "memory\\selected_well" and after that "memory\\well_buffer"
#output_var = arcpy.analysis.Select(in_features, out_feature_class, SQL_Expression)
Well_Location_SQL = arcpy.analysis.Select(Well_Location_SDE,"memory\\selected_well", SQL_Expression)
arcpy.AddMessage("SQL expression applied")

# Truncating FGDB
arcpy.AddMessage("FGDB truncated")

# Appending from SDE to FGDB, Well_Location_FGDB, "TEST")
arcpy.AddMessage("Append from SDE to FGDB completed")

# Make buffer
#arcpy.analysis.Buffer(in_features, out_feature_class, Radius_Buffer)
arcpy.analysis.Buffer(Well_Location_FGDB, "memory\\well_buffer", Radius_Buffer)
arcpy.AddMessage("Buffer completed")

# Use describe to get path to FGDB for creating table for Min & Max results
arcpy.env.workspace = desc.path
arcpy.AddMessage("The path to FGDB is:")

# Create table for output Min & Max
arcpy.CreateTable_management(desc.path, "Stats_GEO")
arcpy.AddField_management("Stats_GEO", "LOCATION_NAME", "TEXT", field_length=100)
arcpy.AddField_management("Stats_GEO", "MIN", "DOUBLE")
arcpy.AddField_management("Stats_GEO", "MAX", "DOUBLE")
arcpy.AddMessage("Creating Table with Min & Max values...")

with arcpy.da.SearchCursor("memory\\well_buffer", ["OBJECTID", "LOCATION_NAME"]) as cursor:
    for row in cursor:
        arcpy.SelectLayerByAttribute_management("memory\\well_buffer", "NEW_SELECTION", "OBJECTID = " + str(row[0]))
        Clipped_Raster =, "", Output_Raster + "_" + str(row[0]), "memory\\well_buffer", "", "ClippingGeometry", "NO_MAINTAIN_EXTENT")
        # Get Raster Properties for bathy raster MINIMUM value
        mini = + "_" + str(row[0]), "MINIMUM", "Band_1")
        # Get Raster Properties for bathy raster MAXIMUM value
        maxi = + "_" + str(row[0]), "MAXIMUM", "Band_1")
        with arcpy.da.InsertCursor("Stats_GEO", ["LOCATION_NAME", "MIN", "MAX"]) as cursor2:
            row2 = [row[1],mini.getOutput(0), maxi.getOutput(0)]
arcpy.AddMessage("Created table for output Min & Max")

# Save the table to excel
arcpy.AddMessage("Saving Stats_GEO table")
arcpy.TableToExcel_conversion("Stats_GEO", Output_Excel)

# Convert results into numbers
maxi_float = float(maxi[0])
mini_float = float(mini[0])

# Print MIN & MAX
arcpy.AddMessage("The maxi_float is: ")

arcpy.AddMessage("The min_float is: ")

# Convert raster to point
arcpy.AddMessage("Converting clipped raster to points and saving to Output_RasterToPoint table")
arcpy.conversion.RasterToPoint(Clipped_Raster, "Output_RasterToPoint")

# Calculate number ranges to avoid rounding problems.
maxi_upper = maxi_float+0.001
maxi_lower = maxi_float-0.001
mini_upper = mini_float+0.001
mini_lower = mini_float-0.001

maxi_upper = maxi_float+0.0001
maxi_lower = maxi_float-0.0001
mini_upper = mini_float+0.001
mini_lower = mini_float-0.001

# Look for a match:
with arcpy.da.SearchCursor("Output_RasterToPoint", ["OBJECTID","grid_code"]) as cursor:
    for row in cursor:
        #Find the max value and print the coordinates
        if row[1] < maxi_upper and row[1] > maxi_lower:
            print("Exact match has been retrieved: ObjID " + str(row[0]))               
            max_OBJID = row[0]
            count = count+1 

        #Find the min value and print the coordinates
        elif row[1] < mini_upper and row[1] > mini_lower:
            print("Exact match has been retrieved: ObjID " + str(row[0]))                
            min_OBJID = row[0]
            count = count+1                    
    print("Exact matches found: " + str(count))

# Make an sql expression to just export the min and max points
sql_exp_select = """{0} = {1} Or {0} = {2}""".format(arcpy.AddFieldDelimiters("Output_RasterToPoint", "OBJECTID"), max_OBJID,min_OBJID)

#Export the points specified in the sql query above.
arcpy.analysis.Select("Output_RasterToPoint","Min_max_points", sql_exp_select)
arcpy.AddMessage("Adding Min&Max table to Contents")'Min_max_points', 'Min_max_points')
arcpy.AddMessage("Min&Max table added to Contents")

# Test for copyig features
#arcpy.CopyFeatures_management("Min_max_points", "Min_max_points_copy3")
#arcpy.AddMessage("Copy dataset")


Not sure what more I can test. If any ideas please let me know. Thanks again!

0 Kudos
MVP Esteemed Contributor

I would call tech support... as soon as you mention "remote server" that might rule out a simple local install issue

... sort of retired...
0 Kudos