Hi, I am having a hard time figuring out how to get my script to export the layout as .jpg. The purpose of the script is that it loops through table and creates new layout based on the row value and then exports that layout. The script works perfectly with exportToPDF, but I can't figure out how to get exportToJPEG to work. Any ideas???
print("\n\tExporting map to pdf...")
finallocationwithPIN = path.join(finallocation, PIN)
if path.exists(finallocationwithPIN):
remove(finallocationwithPIN)
else:
pass
if not lyt.mapSeries is None:
ms = lyt.mapSeries
lyt.mapSeries.refresh()
if ms.enabled:
ms.currentPageNumber = ms.getPageNumberFromName(PIN)
ms.exportToPDF(finallocationwithPIN)
Solved! Go to Solution.
In your example the layout object is the "lyt" object. Instead of using the mapseries in your loop, you just export the layout because after you set the active page the layout object holds that page.
So instead of the last line being "ms.exportToJPEG" it would be "lyt.exportToJPEG"
Sorry for the formatting I'm on mobile
what does print(finallocationwithPIN) return?
R_
It returns the final location of where I want the layouts exported to.
When I run script with exportToJPEG, the error I get is..
AttributeError: 'MapSeries' object has no attribute 'exportToJPEG'
print("\n\tExporting map to pdf...")
finallocationwithPIN = path.join(finallocation, PIN)
if path.exists(finallocationwithPIN):
remove(finallocationwithPIN)
else:
pass
if not lyt.mapSeries is None:
ms = lyt.mapSeries
lyt.mapSeries.refresh()
if ms.enabled:
ms.currentPageNumber = ms.getPageNumberFromName(PIN)
ms.exportToJPEG(f'{finallocationwithPIN}.jpg')
The MapSeries itself has no exportToJPEG method is what's going on. What you're supposed to do is set the map series current page (as you are doing) and then export from the Layout object. I believe that means your last line should be:
lyt.exportToJPEG(finallocationwithPIN)
Can you explain the what you mean by export from the layout object?
Take a look at example 2 here: MapSeries—ArcGIS Pro | Documentation. It's quite similar (I think) to what you're hoping to do.
In your example the layout object is the "lyt" object. Instead of using the mapseries in your loop, you just export the layout because after you set the active page the layout object holds that page.
So instead of the last line being "ms.exportToJPEG" it would be "lyt.exportToJPEG"
Sorry for the formatting I'm on mobile
AH I see! Thank you for pointing out issue so clearly!! I was so deep in the weeds I was missing the obvious! Much appreciation!