Python Scripting in ArcGIS Pro 2.2.1

458
1
08-13-2018 03:07 PM
FreeTrial
New Contributor

I am currently evaluating ArcGIS Pro. I have created a python script to add a feature class of points created from a table. If I load the script directly into the ArcGIS Pro IDE the script runs successfully and adds the feature class to the map containing the points. However, if I run the same script through a toolbox or python toolbox, ArcGIS claims it ran successfully, but the feature class is not added. The toolbox creates the file and saves it in the current geodatabase, but I have to add it manually. Do you have to add additional code in the toolbox scripts to force the add of the feature class to the map?

Tags (3)
0 Kudos
1 Reply
KoryKramer
Esri Community Moderator

It looks like we have an enhancement request asking for the difference to be better explained in the help:

[ENH-000105422: Please document differences in the addOutputsToMap environment setting between scripts run from a toolbox and scripts run from the Python window.]

From that request, "In ArcGIS Pro, when the addOutputsToMap environment property is set to True, and a script is run from the Python window, a new layer created in the script is automatically added to an open map. This is not the case when running a script from a toolbox. In the latter case, it is necessary for the script to have an output parameter for the layer or feature class created in the script. The parameter can be either Output or Derived, but the new layer won't be added to the map unless such a parameter is present."

So to answer your question, yes, there is a difference and if running from a toolbox, you'll need to modify the script slightly to create an output parameter for the layer or feature class created in the script.  Hope this helps.

0 Kudos