Refresh Map after python script

402
6
02-21-2024 07:42 AM
melisahansen
New Contributor III

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

Tags (2)
6 Replies
DanPatterson
MVP Esteemed Contributor

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


... sort of retired...
0 Kudos
melisahansen
New Contributor III

@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!

0 Kudos
DanPatterson
MVP Esteemed Contributor

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.


... sort of retired...
0 Kudos
melisahansen
New Contributor III

@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. 

0 Kudos
DanPatterson
MVP Esteemed Contributor
I didn't see any obvious bugs on the Tech Support site https://support.esri.com/en-us/overview you could have a look, or file a tech support issue

... sort of retired...
0 Kudos
AlderMaps
Occasional Contributor

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.

Initial iteration of script.

0 Kudos