Select to view content in your preferred language

Prevent arcpy functions from adding output to a map

6724
4
Jump to solution
05-13-2021 04:50 PM
davedoesgis
Frequent Contributor

Short version: Is there some way to tell ArcPy functions running in Pro (command prompt or Notebook) whether or not to add the output as layers on a map? For example, ModelBuilder has an "Add to Display" variable to control whether a step's output is added to a map. Is there some equivalent in ArcPy? 

Many Python ArcPy functions running in the Python prompt or a Pro Notebook will add the output to your active map. That's either super handy or super annoying, depending on whether you want the function's output on your map. Sometimes I'm just working with data in an FGDB that has nothing to do with a map (e.g.: arcpy.management.AlterField) and layers start appearing on the map. Other times, I am interacting with a map, but my code has a bunch of intermediate steps that don't need to be on the map. Also, my code runs a LOT faster when it's not adding layers to the map. 

If I close all my maps and run the code, this doesn't happen. After re-opening one or more maps, it may not start doing this again. So clearly I don't understand the how or the why about ArcPy adding layers to maps. I know how to programmatically add and remove the layers from the map, so I can solve this, but I'd rather be able to control whether they were added (or not) in the first place. 

 

0 Kudos
2 Solutions

Accepted Solutions
Tim_McGinnes
Frequent Contributor

arcpy.env.addOutputsToMap = False

https://pro.arcgis.com/en/pro-app/latest/arcpy/classes/env.htm 

addOutputsToMap (Boolean) - The tool's resulting output datasets will be added to the application display. The property is only applicable when used directly in the Python window or from a Notebook in ArcGIS Pro.

View solution in original post

DanPatterson
MVP Esteemed Contributor

Always on for me, try toggling it off

toggle.png


... sort of retired...

View solution in original post

4 Replies
Tim_McGinnes
Frequent Contributor

arcpy.env.addOutputsToMap = False

https://pro.arcgis.com/en/pro-app/latest/arcpy/classes/env.htm 

addOutputsToMap (Boolean) - The tool's resulting output datasets will be added to the application display. The property is only applicable when used directly in the Python window or from a Notebook in ArcGIS Pro.

davedoesgis
Frequent Contributor

I'm pretty sure I looked here for this, but jeez, it's the very first property under env in the docs, haha. Thanks, this works great! 

0 Kudos
DanPatterson
MVP Esteemed Contributor

Always on for me, try toggling it off

toggle.png


... sort of retired...
davedoesgis
Frequent Contributor

I didn't try this, since I was looking for a solution in Python, but it seems like this would also do the trick using the GUI. The only issue with this I suppose is that you can't toggle it on/off/on/off during a script's execution. 

0 Kudos