How to overwrite input parameter with output parameter in ArcPy?

1764
12
Jump to solution
03-30-2022 12:44 AM
DanaNajeeb
New Contributor II

I created a custom geoprocessing tool using Python in ArcGIS Pro and published it to use in Web AppBuilder. The results show with no issues in ArcGIS Pro, however, in Web AppBuilder, they don't, I believe the issue has to do with not specifying the output parameter correctly.

My issue now is how would I specify the output parameter to be the same as the input parameter? I added the arcpy.env.overwriteOutput = True and I did set the output parameter to be derived. But when I run the tool, it doesn't give me any errors and it tells me that the results are drawn on the map, but the changes are not implemented.

Not too sure what I'm doing wrong.

Here's my Python script:

 

arcpy.env.overwriteOutput = True

#Inputs

Point1 = arcpy.GetParameterAsText(0)
Point2 = arcpy.GetParameterAsText(1)
Polygon = arcpy.GetParameterAsText(2)

#Outputs

out1 = arcpy.SetParameter(3, Point1)
out2 = arcpy.SetParameter(4, Point2)


# Select points that overlap the polygon
selected_points = arcpy.SelectLayerByLocation_management(Point1, 'INTERSECT',
Polygon)

#Append selected points to the other layer.
arcpy.Append_management(selected_points, Point2, 'NO_TEST')

#Deelete selected points from the original layer

arcpy.DeleteFeatures_management(selected_points)

 

0 Kudos
1 Solution

Accepted Solutions
Luke_Pinner
MVP Regular Contributor

out1 = arcpy.SetParameter(3, Point1)
out2 = arcpy.SetParameter(4, Point2)

Should probably be at the end of the script. You're setting the outputs before doing anything with them. Try something like:

arcpy.env.overwriteOutput = True

#Inputs
Point1 = arcpy.GetParameterAsText(0)
Point2 = arcpy.GetParameterAsText(1)
Polygon = arcpy.GetParameterAsText(2)

# Select points that overlap the polygon
selected_points = arcpy.SelectLayerByLocation_management(Point1, 'INTERSECT',
Polygon).getOutput(0)

#Append selected points to the other layer.
arcpy.Append_management(selected_points, Point2, 'NO_TEST')

#Delete selected points from the original layer
arcpy.DeleteFeatures_management(selected_points)

OutPoint1 = arcpy.management.MakeFeatureLayer(Point1, "Point1")
OutPoint2 = arcpy.management.MakeFeatureLayer(Point2, "Point2")

#Outputs
out1 = arcpy.SetParameter(3, OutPoint1)
out2 = arcpy.SetParameter(4, OutPoint2)

View solution in original post

0 Kudos
12 Replies
DanPatterson
MVP Esteemed Contributor

Just a thought.  Since delete features will do this to features that are selected, shouldn't you be deleting them from Point1 in your last line rather than the layer "selected_points".


... sort of retired...
0 Kudos
DanaNajeeb
New Contributor II

Thank you for your response. That makes sense, I changed it to Point1 and it still works. It's just that I'm having the same problem still.

0 Kudos
DanPatterson
MVP Esteemed Contributor

MakeFeatureLayer is used as a step in the process, It may not be being done in the webapp environment


... sort of retired...
0 Kudos
DanaNajeeb
New Contributor II

I'm not sure I've done this correctly, but here's my script after adding MakeFeatureLayer and it gives the same behavior:

DanaNajeeb_0-1648649044596.png

 

 

0 Kudos
DanaNajeeb
New Contributor II

I also tried to add the MakeFeatureLayer after setting the variables, same thing

0 Kudos
Luke_Pinner
MVP Regular Contributor

How are parameters 3 & 4 defined in the toolbox? Data type, type, direction especially. Can you provide a screenshot of the toolbox script parameter properties?

0 Kudos
DanaNajeeb
New Contributor II

Sure, here's a screenshot.

For the dependency tab, I tried with and without it. But I don't seem to have the "Add result as operational layer" option available in the Web AppBuilder, in the widget settings, unless I specify the dependency parameter.

DanaNajeeb_0-1648716017058.png

 

0 Kudos
Luke_Pinner
MVP Regular Contributor

out1 = arcpy.SetParameter(3, Point1)
out2 = arcpy.SetParameter(4, Point2)

Should probably be at the end of the script. You're setting the outputs before doing anything with them. Try something like:

arcpy.env.overwriteOutput = True

#Inputs
Point1 = arcpy.GetParameterAsText(0)
Point2 = arcpy.GetParameterAsText(1)
Polygon = arcpy.GetParameterAsText(2)

# Select points that overlap the polygon
selected_points = arcpy.SelectLayerByLocation_management(Point1, 'INTERSECT',
Polygon).getOutput(0)

#Append selected points to the other layer.
arcpy.Append_management(selected_points, Point2, 'NO_TEST')

#Delete selected points from the original layer
arcpy.DeleteFeatures_management(selected_points)

OutPoint1 = arcpy.management.MakeFeatureLayer(Point1, "Point1")
OutPoint2 = arcpy.management.MakeFeatureLayer(Point2, "Point2")

#Outputs
out1 = arcpy.SetParameter(3, OutPoint1)
out2 = arcpy.SetParameter(4, OutPoint2)
0 Kudos
DanaNajeeb
New Contributor II

I tried that, still worked in ArcGIS Pro, but unfortunately, didn't change anything in the layer in Web AppBuilder. Thank you though!

 

0 Kudos