0

I'm attempting to run a simple tool script in ArcGIS Pro 2.4 that creates a feature layer from an existing layer. The script creates the feature layer just fine if running the script in PyCharm, as well as the Python interpreter within ArcGIS (adds visible feature layer under Maps).

Why would the layer not be created and be visible in ArcGIS pro if running the script as a tool, compared to running it externally or in the interpreter?

Anyone else having this issue with 2.4 when running scripts as a tool?

No errors.

p = arcpy.mp.ArcGISProject("CURRENT")
a_map = p.activeMap
lyrs = a_map.listLayers()
# Checking layers within activeMap, they exist
for l in lyrs:
 arcpy.AddMessage("{0}: activeMap layer: ".format(l))

# Feature layer not created when used as a tool, but works in the Python interpreter & external PyCharm run
arcpy.MakeFeatureLayer_management(a_map.listLayers('countries')[0], 'test')

1 Answer 1

2

Determined the problem for anyone else running into this issue. I just needed to return the new layer as output, then add that layer to the map. I discovered this by finding a setting selected in ->Project->Options->Geoprocessing "Add output datasets to open map".

out_lyr = a_map.listLayers('countries')[0]
new_lyr = arcpy.MakeFeatureLayer_management(out_lyr, 'tester').getOutput(0)
a_map.addLayer(new_lyr)
4
  • Did you have to change that setting in ArcGIS Pro or just update your code like you did in your answer? I'm having the same problem where my script is not adding the layer. Jul 17, 2020 at 14:19
  • I had to update the setting above , while also updating my code. If the "add output datasets to open map" is not checked off, nothing will be added to the map. But, if you update the code as well to the above, the settings will read the new layer as an output dataset and add that layer to the map.
    – Kamakazi
    Jul 17, 2020 at 17:49
  • Just to clarify, do you uncheck that setting or leave it checked? Jul 17, 2020 at 18:59
  • It should be enabled, or checked.
    – Kamakazi
    Jul 18, 2020 at 19:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.