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()
@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
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
@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.
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.
For me it is changing the text in a text element. I have it set to Align Center in the Layout but if a change the text out in script it does not recenter at all so it looks terrible. What is the point of being able to change the text if it does not realign? I must be missing something.
Hi, I would like to second this request. I am having trouble with my script that runs a series of geoprocessing tools on data to generate new buffer and line features from points in a feature class and then outputs a series of PDFs that are supposed to include the newly generated features in the maps. The script used to work fine in earlier versions of Pro, but for about four months the newly generated features are not visible in the exported PDFs. Once the script tool is completed, if I hit refresh in the layout window of the APRX, then the new features show up just fine. Sometimes (but not always) the features also show up just fine automatically in the layout once the script tool is finished, but by that point the PDF has been exported without the features showing up.
I've noticed that when the lock icon is on the layers in the table of contents during and after the geoprocessing tools that affect them are run, the features will not draw. As soon as that lock icon disappears (like if the script crashes for some other reason), usually (but not always) the newly generated features will immediately appear in the layout. I have not been able to figure out a way to get it to release the lock as a workaround either. I have also tried putting in arcpy.RefreshLayer and the CIM hack you mentioned above and having the script clearing out the workspace cache, but those haven't made a difference.
This is complicating my workflow because I am having to manually save out an APRX for each newly generated feature, open up that APRX, and then export the PDF from that as I cannot get Pro to output the PDFs properly with the script tool. A simple way in Arcpy to have Pro refresh the layout would be great.
@DougBrowning are you working straight text? With straight text, regardless of alignment if you change the string to be something shorter, the text envelope that contains the text will be left aligned since that is the anchor point location. If you change the anchor position to center and then modify the string, it should stay center aligned.
Jeff - arcpy.mp and Layout (SDK) teams.
@asmith_tssw could you share a small snippet of code that demonstrates what the script tool is doing?
Thanks,
Jeff - arcpy.mp and Layout (SDK) teams
@JeffBarrette Hi Jeff, thanks for responding. I'm not sure where to start to send a small snippet. My script tool is a 683 line long script that does a lot of geoprocessing operations before a loop runs to generate maps and PDF exports. How would you suggest I begin to show you the problem?
Thanks,
Alex
@asmith_tssw - I need a reproducible case and it is so difficult to know what your script is doing and how it is interacting within the application. For example, are you running script tool within the application or are you running a stand-alone script outside of the application? Even if you could provide a bulleted list of the order of operations, that could be helpful.
Jeff
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.