1

I'm trying to create three map layouts and export them into PDFs using ModelBuilder in ArcGIS Pro. However, when I try to reference the three bookmarks (AAA, Amityville, and Astoria) to be used for the layouts, I get an error.

Here is a section of my code from a custom script tool that I am having trouble with:

# setting layout to bookmark
aprx = arcpy.mp.ArcGISProject("Current")

# add name of layout
lyt = aprx.listLayouts("Layout_King")[0]
mf = lyt.listElements("MAPFRAME_ELEMENT")[0]

# add name of bookmark
bkmks = mf.map.listBookmarks('AAA','Amityville','Astoria')
bkmks.sort(key=lambda x: x.name, reverse=True)
for bkmk in bkmks:
  mf.zoomToBookmark(bkmk)
  legend.autoAdd = True
  time.sleep(5)
  lyt.exportToPDF(r"C:\arcGIS_Shared\Exports" + "\\" + bkmk.name + ".pdf") 

The error I'm getting is:

Traceback (most recent call last):
  File "C:\arcGIS_Shared\PythonTest_2\Layout_Bookmark_Export_Script.py", line 42, in <module>
    bkmks = mf.map.listBookmarks('AAA','Amityville','Astoria')
TypeError: listBookmarks() takes from 1 to 2 positional arguments but 4 were given
Failed to execute (Layout Bookmark Export)

1 Answer 1

2

From the documentation, listBookmarks can take a wildcard to search on. You cannot pass three parameters to it, like you are doing.

Try something like:

bkmks = mf.map.listBookmarks('A*')

One alternative would be to retrieve all the bookmarks, then in your loop below, check to see if they are in your list.

# add name of bookmark
bkmks = mf.map.listBookmarks()
bkmks.sort(key=lambda x: x.name, reverse=True)
for bkmk in bkmks:
  if bkmk.name in ['AAA','Amityville','Astoria']:
       mf.zoomToBookmark(bkmk)
       legend.autoAdd = True
       time.sleep(5)
       lyt.exportToPDF(r"C:\arcGIS_Shared\Exports" + "\\" + bkmk.name + ".pdf")

Note: this is untested code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.