Adding results from geoprocessing scripts to ArcGIS Pro

by smh   Last Updated April 16, 2018 06:22 AM

I am in the process of updating scripts and models from ArcGIS Desktop to work in Pro however I'm having difficulty getting results from geoprocessing operations to display in the map window.

As an example, for the following snippet:

import arcpy
arcpy.env.overwiteOutput = True
aprx ="CURRENT")
m = aprx.listMaps("*")[0]
inputFC = arcpy.GetParameterAsText(0)
outputWorkspace = arcpy.GetParameterAsText(1)
outputFC = arcpy.GetParameterAsText(2)
outputFC = outputWorkspace + "\\" + outputFC
arcpy.MultipartToSinglepart_management(inputFC, outputFC)
outputLyr = arcpy.MakeFeatureLayer_management(outputFC, "outputLyr")
m.addLayer(outputLyr, "TOP")

I get the error: "ValueError: outputLyr". The process completes successfully, it's just that I can't get the result to add to the map.

My knowledge of python is quite limited but as I understand it, a feature class needs to be made into a layer before being added to the map. Previously in Desktop we used the following:

layer_file = arcpy.mapping.Layer(outputFC)
arcpy.mapping.AddLayer(dataframe, layer_file)

Can't work out where I'm going wrong. Any advice is much appreciated.

Related Questions