Select to view content in your preferred language

Layout Refresh method for arcpy.mp

351
4
07-22-2024 09:01 AM
Status: Open
Labels (1)
HaydenWelch
Frequent Contributor

Currently there is no way to "refresh" a standard Layout object using the mp module. You can however refresh a mapseries.

 

import arcpy.mp as mp

# Current behavior for mapseries
project = mp.ArcGISProject("CURRENT")
layout = project.listLayouts()[0]
layout.mapSeries.refresh()

# Desired behavior for layouts
project = mp.ArcGISProject("CURRENT")
layout = project.listLayouts()[0]
layout.refresh()

 

Tags (2)
4 Comments
JeffBarrette

@HaydenWelch , thanks for the feedback.  I'd like to know what type of layout elements are not updating for you.  Ideally, layouts should automatically refresh on their own without having force a refresh.

There are some core geoprocessing operations that may update data behind the scenes that doesn't trigger components in the app to refresh.  At Pro 3.3 the core Arcpy team introduced arcpy.RefreshLayer() that should trigger the appropriate updates in the App when data is being modified.

Another way to get the Layout to redraw is to use something like:

p = arcpy.mp.ArcGISProject('current')
lyt = p.listLayouts('Some Layout')[0]
lyt_cim = lyt.getDefinition('V3')
lyt.setDefinition(lyt_cim)

The code above forces the layout and its elements to redraw BUT DOES NOT force underlying data to update.  That is what arcpy.RefreshLayer().

MapSeries.refresh() is for situations where data in the index layer has been updated.  Think of it as a specialized version of arcpy.RefreshLayer().

If this helps solve your issue, great, but if you there is a reason you really need to refresh a layout that is not data specific, please let us know.

Jeff - Layout and arcpy.mp teams

HaydenWelch

@JeffBarrette

Thanks for that code snippet! I always forget to dig into the CIM for doing layout stuff. It can get daunting.

In my scenario the layouts tend to have multiple maps that they reference and getting the layout to update during an exportToPDF call needed to be done manually using the refresh button in the bottom right of the layout interface.

I'm going to test out the forced CIM update to see if that works (it should), but I just noticed that there's not an intuitive way to "refresh" a layout that matches the functionality of the refresh button in the Layout interface in Pro

JeffBarrette

@HaydenWelch I completely understand your point of view.  Are you also saying that in the UI, you have to refresh to ensure you get the proper export?  That would definitely be a bug (the UI export or arcpy.mp export should always render proper output).   Pro should automatically update and we purposely did not include a refresh option (like we had in ArcMap arcpy.mapping) because Pro's underlying architecture/services should do the automatic refresh. If they are not working, then we need to address that.  It might be possible to provide a refresh option but I want to make sure we are providing the correct solution.  Refresh my be a workaround but also an unnecessary step that will also be a performance hit.

I hope this make sense. If I could get some clarification on your workflow and possible repro steps, then we can make sure a proper fix/solution is provided.

HaydenWelch

@JeffBarrette 

Huh, I've definitely got an edge case here. I'm going to do some internal testing and get back to you if I find out what's causing the issue. I just tested it on some other templates and it works fine with the builtin refreshing. It could be that we've built some complex queries and calculations into some of the dynamic text and tables. The issue is also bad on layouts with large image files, but when testing in isolation the large images only caused the update to be delayed and not ignored.

Could a cache/memory limit be causing issues? say if 20+ layouts were all referencing the same queried layer with dynamic text functions?

For now though your solution of forcing a CIM update is working. It seems that the issue is primary with dynamic text objects not being auto refreshed on export and updating the CIM that way fixes it.