Tuesday, December 18, 2012

Using env.addOutputsToMap

The environmental variable addOutputsToMap prevents geoprocessing task results from being displayed in the TOC.  This environmental property by default is set to true, so every tool's result will display in the table of contents in ArcMap.

When developing python add-ins, you should utilize this tool to prevent sub-processes results from being added to the map.  A good example of this, is if your python add-in creates a table if it doesn't exist for logging purposes.  Your end user does not want to see this table, or know it exists, but if addOutputsToMap is set to true, the value will display in the table of contents.  Changing it to false would prevent the data from showing.

Example:
from arcpy import env
env.addOutputsToMap = false
#... perform GP task...
env.addOutputsToMap = true

Enjoy

2 comments:

Poormanphysics said...

I tried this like here:
class LicenseError(Exception):
pass

import arcinfo
import arcpy
from arcpy import env

env.addOutputsToMap = True
arcpy.env.workspace = "D:/Bohol_Data/USC_SAR_DEM"

try:
if arcpy.CheckExtension("3D") == "Available":
arcpy.CheckOutExtension("3D")
else:
# raise a custom exception
raise LicenseError

arcpy.HillShade_3d("usc", "usc_hill", 300)
arcpy.Aspect_3d("usc", "usc_aspect")
arcpy.CheckInExtension("3D")

except LicenseError:
print "3D Analyst license is unavailable"
except:
print arcpy.GetMessages(2)

env.addOutputsToMap = False

It does not add anything to the TOC but I see the generated files on the connected folder?

Why is this result?

Andrew said...

If you want to add the results to the map, you do not need to set the env.addOutputsToMap, true is default.

Did you try refreshing your desktop TOC by pushing the refresh button?