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.
-
1Can you expand your code sample and show a real example of what the function do_something() is doing. By obfuscating your code the issue may lie within that function?Hornbydd– Hornbydd2021年11月12日 16:50:12 +00:00Commented Nov 12, 2021 at 16:50
-
1Do you absolutely need it to be a parameter? The last time I looked at this scenario there was nothing more that could be done than you've discovered. (Maybe things have changed). But generally, if something is a parameter, the app is going to add it to the map on execution unless the global GP setting has been turned off.KHibma– KHibma2021年11月12日 16:50:59 +00:00Commented Nov 12, 2021 at 16:50
-
@KHibma, originally I didn't have a derived output parameter but if I'd like to use the result in a model, I wouldn't able to do so. If the answer to my question is that it's not possible, that's also an answer and I can stop searching for a solution. ;)Thomas– Thomas2021年11月12日 17:16:06 +00:00Commented Nov 12, 2021 at 17:16
-
@Hornbydd, 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.Thomas– Thomas2021年11月12日 17:25:10 +00:00Commented Nov 12, 2021 at 17:25
-
2Well - if you're using your PYT as a sub-tool to a model, and within the model this output IS NOT a model parameter, then I'd expect that it not be added to the display. But you're right, you need the PYT to have a parameter to make it chainable in the model. (just don't put the "P" on it)KHibma– KHibma2021年11月12日 17:30:03 +00:00Commented Nov 12, 2021 at 17:30
1 Answer 1
If your output is a derived parameter, it will by displayed accordingly to the environnement variable arcpy.env.addOutputsToMap
from the active map or from an other tool/model that contains your tool script.
You cannot set this option directly in your tool script with a derived parameter.