ArcGIS 10.3.x Python tool script - Automatically adding multivalue output feature class to display

2096
3
06-23-2016 05:44 AM
FrancescoTonini2
Occasional Contributor II

I am developing a Python tool script in ArcGIS 10.3.x that is meant to be later published as a GP service and consumed inside a web application (e.g. built with ESRI JS API). The tool script produces two output feature classes (see below) that I would like to automatically add to the display. Usually one would set the tool output to derived in order to accomplish that. In my tool properties, I have a derived output parameter, set to multivalue to accommodate multiple feature classes that are created in the script. However, once the script is done running, none of the two output feature classes (correctly written to my scratch GDB) show up in the TOC in ArcMap, which would be necessary before publishing it as a GP service. Anyone has an idea what am I doing wrong?

Code Example:

============

import arcpy
import os

inTable
= arcpy.GetParameterAsText(1)
startX_field
= arcpy.GetParameterAsText(2)
startY_field
= arcpy.GetParameterAsText(3)
endX_field
= arcpy.GetParameterAsText(4)
endY_field
= arcpy.GetParameterAsText(5)
lineType_str
= arcpy.GetParameterAsText(6)
SpRef = arcpy.GetParameterAsText(7)

outList
= []

# XY To Line
flowsOutputFC
= os.path.join(arcpy.env.scratchGDB, "FlowLines")

arcpy
.XYToLine_management(in_table=inTable, out_featureclass=flowsOutputFC,
                          startx_field
=startX_field, starty_field=startY_field,
                          endx_field
=endX_field, endy_field=endY_field,
                          line_type
=lineType_str, spatial_reference=SpRef)

outList
.append(flowsOutputFC)

nodesOutput
= "DestNodes"
arcpy
.MakeXYEventLayer_management(table=inTable, in_x_field=endX_field,

                                  in_y_field=endY_field, out_layer=nodesOutput)

nodesOutputFC = os.path.join(arcpy.env.scratchGDB, "DestNodesFC")
arcpy
.CopyFeatures_management(in_features=nodesOutput, out_feature_class=nodesOutputFC)
outList
.append(nodesOutputFC)

results
= ";".join(outList)
arcpy
.SetParameterAsText(8, results)

0 Kudos
3 Replies
DanPatterson_Retired
MVP Emeritus

Just as a check ,In the geoprocessing, geoprocessing options, ensure that

results are temporary by default is toggled off

add results to display  is toggled on

GeoprocessingOptions.png

0 Kudos
FrancescoTonini2
Occasional Contributor II

Dan, thanks for the answer. I do have the correct settings in the GP, as you suggested. Does not seem to be the issue.

0 Kudos
DanPatterson_Retired
MVP Emeritus

short of adding a few print statements in to ensure something is being created and received between steps, no.  Those tools won't necessarily throw an error if nothing is being created or saved.

0 Kudos