I wrote a Python Toolbox and would like to suppress it from adding output datasets to the active map. Below a minimal example (not the actual toolbox):
import arcpy
from typing import List
class Toolbox(object):
def __init__(self):
self.label = "Toolbox"
self.alias = "Toolbox"
self.tools = [Tool]
class Tool(object):
def __init__(self):
self.label = "Tool"
self.description = "Tool Skeleton"
def getParameterInfo(self) -> List[arcpy.Parameter]:
output_feature_classes = arcpy.Parameter(
name="output_feature_classes",
displayName="Output Feature Classes",
datatype="DEFeatureClass",
parameterType="Derived",
direction="Output",
multiValue=True,
)
return [output_feature_classes,]
def isLicensed(self) -> bool:
return True # always licensed
def execute(self, parameters: List[arcpy.Parameter], messages):
# arcpy.env.addOutputsToMap = False
result = do_something()
# make available for next tool
parameters[0].value = result.feature_classes
return result
arcpy.env.addOutputsToMap = False
does apparently only work when used directly in the Python window or from a Notebook in ArcGIS Pro.
arcpy.env.addOutputsToMap
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. (https://pro.arcgis.com/en/pro-app/latest/arcpy/classes/env.htm)
How can I suppress ArcGIS Pro from adding my output to the active map if this is the only tool (or the last tool of a model) being run?
(I am aware of that if I use the tool in a model, I can configure if add or not add intermediate output to the map. I am also aware of that there is a global setting in Options.)
Note: The return value of do_something()
is a namedtuple
and its property feature_classes
is an array of created feature classes. The code behind do_something()
is completely decoupled from the Python toolbox.