There has been similar post in the past regarding being able to refresh the map after a python script has run, has there been any updates to this or is there still no solution. The thread below was from 2017, and I have not found a good solution still. There seems to be no resolution to the previous thread about this.
ArcGIS Pro | ArcPy - How To Refresh the Map - Esri Community
Nothing has changed if you are running a python script outside of an active Pro project.
Where are you running it?
Tool in a toolbox you created?
script from the python window inside Pro?
notebook from within Pro?
separate IDE?
first 3 will update, the last won't
@DanPatterson Hi Dan, we are running a tool from a toolbox, the data/map does not refresh in ArcPro. In ArcMap these tools worked and you could see the data created by the tool, this is not the case in Pro. Previously we used:
def RefreshMap ():
mxd = arcpy.mapping.MapDocument('CURRENT')
df = arcpy.mapping.ListDataFrames(mxd, "Layers") [0]
df.zoomToSelectedFeatures()
arcpy.RefreshActiveView()
This does not work in Pro, and we have not found an equivalent option other than closing the project and reopening, which is not sufficient. And using the refresh at the bottom right of the screen also does not work. These are the same issues from the previous thread I shared. Thanks!
Strange, perhaps the rest of your code needs a look at
Migrating from arcpy.mapping to ArcGIS Pro—ArcGIS Pro | Documentation
The application always refreshes when using CURRENT
When you use the CURRENT keyword in the Python window with ArcGIS Desktop, you sometimes had to call refreshActiveView to force a screen refresh. This is no longer the case with ArcGIS Pro. All arcpy.mp API changes directly update ArcGIS Pro.
@DanPatterson this seems to be the issue for many people. If you look at the link I posted many people discuss the "current" keyword and how it does not work. It seems that when a tool is ran that creates data, the layer does not refresh, and you cannot see the data until you close and reopen the project.
I have had a similar issue with an ArcPy script that is part of an ongoing project. ArcPy script in a Notebook run in ArcGIS Pro. Mine is intended to automate cartographic production; it cycles through calc'ing some fields based on imports from an Excel file, then exporting a layout, wash rinse repeat.
My issue was that not all the layers would draw/refresh in the automated map export. I confirm that the data has actually been updated, and if I refresh the layout manually in Pro, the symbols/labels update per calculated data. But during troubleshooting, often there was a single stubborn layer that would not show up in the automated layout export.
For my first iteration of the script, I was never able to nail down exactly what the issue was, but I defeated it by including an extra map frame, hidden beneath the main map frame, and if that frame was active during the script run, things exported correctly (I know, bizarre 😅).
Incorporating additional functionality into the script now and my old nemesis is back. This is a new thread since I last searched here, so following to see if anyone comes up with any insight on how to force the layout to refresh before exporting it.
UPDATE 6/4/24: Based on some comments made in this post, I came up with a workaround I will be using for this issue going forward. Prior to a single iteration of exporting the map, I (programmatically) remove all the layers from the map, then re-add them from a .lyrx file, then perform the export. Only other adjustment I had to make to the layout was to lock down the extent of all the map frames via constraints (so the basemap layers didn't force the map to zoom to a global extent). Otherwise it is working as the "refresh" I needed for these scripts.