AnsweredAssumed Answered

Refresh Data after Python Tool Execution

Question asked by colgateg on Oct 12, 2020
Latest reply on Oct 13, 2020 by bixb0012

By all documentation that I can find ArcPro should refresh the data in a map after running a custom geoprocessing tool. This has not been my experience so far. I have tried to make this tool several different ways. The edit completes successfully, but does not show in the map unless I refresh the map view in the versioning tools. Some think that the automatic refresh will be triggered if the tool has a derived output. Others have said that it will be triggered after the arcpy.da.Editor operation is closed as long as we are working in the "CURRENT" but not sure what that means in determining a workspace. The example below incorporated all of the documented recommendations without success.


All we want is a simple tool that updates a select number of attributes on an existing layer and saves them inside of the current version (shown in the map without additional action by user). Any recommendations appreciated.


Built with ArcPro 2.6.2 using the New Script wizard with a single input param and a single derived output param:


# Import system modules
import arcpy
# Set the parameters
InputIDF = arcpy.GetParameterAsText(0)
#Process: Start Edit
prev_workspace = arcpy.env.workspace
arcpy.env.workspace = arcpy.Describe('GPS').Path
edit = arcpy.da.Editor(arcpy.env.workspace)
arcpy.SelectLayerByAttribute_management('GPS', 'CLEAR_SELECTION')
with arcpy.da.UpdateCursor('GPS',['IDFEATURE','QAPNTUSE'],'IDFEATURE={}'.format(InputIDF)) as cursor:
for row in cursor:
row[0] = None
row[1] = 5
del cursor
# Cleanup
arcpy.env.workspace = prev_workspace
# Set layer as output param
m = p.listMaps()[0]
l = m.listLayers('GPS')[0]
arcpy.SetParameter(1, l)