Exporting Bookmarks In ArcGISPro ArcPy

980
6
11-28-2018 10:30 AM
ProvidenceAdu
New Contributor III

Dear All,

I have a question for exporting bookmarks, This script exports bookmarks from "Vic layout", I wanted to ask, if it is possible, to reference, bookmarks in a different layout/map, and export it. If yes, what should I change in the script. All the bookmarks are in the same project. Dan Patterson Python

Tags (1)
0 Kudos
6 Replies
DanPatterson_Retired
MVP Emeritus

Code formatting would help with line numbers

/blogs/dan_patterson/2016/08/14/script-formatting 

From ….

ArcGISProject—ArcPy | ArcGIS Desktop 

The general syntax (in your case) would be....

for lyt in aprx.listLayouts():

and if you want to export all the bookmarks from all the layouts, then you have to indent your last 3 lines so that they are with the main loop

0 Kudos
ProvidenceAdu
New Contributor III

Hi Dan, Thank you for the quick response.  The loop works perfectly for the layout that has the bookmarks, but I want to zoom those same Bookmarks in a different layout.  

I have four different layouts (Vic Layout, Zone Layout, Hist Layout, Prep Layout) with different contents (Map Frame Elements).

I created the bookmarks using the map in Vic Layout, but the script currently doesn't allow me to reference these Bookmarks in Zone Layout, Hist Layout, or Prep Layout, it returns an empty out.

So my question is how do I reference or zoom to these bookmarks in Zone Layout, Hist Layout, and Prep Layout in the script, export them.

This code works perfectly: 

import arcpy
aprx = arcpy.mp.ArcGISProject(r"Y:\Pro\Research\Books.aprx")
for lyt in aprx.listLayouts("Vic Layout*"):
   mf = lyt.listElements("MAPFRAME_ELEMENT")[0]
   bkmks = mf.map.listBookmarks()
   for bkmk in bkmks:
      mf.zoomToBookmark(bkmk)
      lyt.exportToJPEG(r"Y:\Pro\Research" + "\\" + bkmk.name)

.. but this doesn't

import arcpy
aprx = arcpy.mp.ArcGISProject(r"Y:\Pro\Research\Books.aprx")
for lyt in aprx.listLayouts("Zone Layout*"):
   mf = lyt.listElements("MAPFRAME_ELEMENT")[0]
   bkmks = mf.map.listBookmarks()
   for bkmk in bkmks:
      mf.zoomToBookmark(bkmk)
      lyt.exportToJPEG(r"Y:\Pro\Research" + "\\" + bkmk.name)


Sorry for the long response, I wanted to give you detailed context so that you could help me. Thank you so much in advance 

0 Kudos
ProvidenceAdu
New Contributor III

Hi Dan Patterson‌, please I am following up on this issue to see if you've got any update from your end. Thank you in advance. 

0 Kudos
DanPatterson_Retired
MVP Emeritus

I was wondering what the ...'but this doesn't ... to be clarified.  Did you get an error? Do all your aprx's have a Zone Layout layout in them? or do those change?

0 Kudos
ProvidenceAdu
New Contributor III

Hi Dan, I don't get an error, it returns an empty output since the map frame in the Zone Layout is not the one used to create the bookmarks. 

I have only one aprx and with multiple layouts, Zone Layout is one of them, the others are : Vic Layout, Hist Layout, Prep Layout. 

I want to able reference the Bookmarks for all the four different layouts, but the bookmarks work only for the layout  (Vic Layout) which contains the map frame used to create the Bookmarks. 

Thank You. 

0 Kudos
DanPatterson_Retired
MVP Emeritus

lost me now... the bookmarks are associated with map frame which is associated with the layout in the aprx, but you are saying that the bookmarks only work for the layout which contains the map frame using to create the bookmarks.  AT this point, I would have a look at what you  have manually to figure out what you have and what it belongs to

0 Kudos