Select to view content in your preferred language

Specific bookmarks for arcpy.mapping.ListBookmarks

693
4
02-27-2014 01:30 PM
DannyLackey
Deactivated User
2 part question:

1.  Trying to output a series of specific bookmarks to a pdf.  I can do it with all bookmarks
for bkmk in arcpy.mapping.ListBookmarks(mxd,"*",df):
or 1 specific bookmark
for bkmk in arcpy.mapping.ListBookmarks(mxd,"Bookmark1",df):
, but how do I get multiple specific bookmarks?  I can't get the syntax right.

Something like
for bkmk in arcpy.mapping.ListBookmarks(mxd,["Bookmark1","Bookmark3"],df):
(doesn't work, though)
Tags (2)
0 Kudos
4 Replies
MichaelVolz
Esteemed Contributor
The parameter you are changing appears to be a filter.  It seems that you would have to have something in common in the name of the bookmarks you want to use if you only want a subset.

If you have bookmarks with names City_LA, City_NY, and State_NM, you could have the filter of City and you would get the first 2 bookmarks.  I think this is how the wildcard parameter works and you cannot use a list like in your example.  If the bookmark names have nothing in common, I believe you are out of luck.
0 Kudos
DannyLackey
Deactivated User
That's unfortunate....

I'll try to find another solution.  thx
0 Kudos
XanderBakker
Esri Esteemed Contributor
Hi Danny,

Suppose when I use the following code:

for bkmk in arcpy.mapping.ListBookmarks(mxd,"*",df):
    print bkmk.name


I get this result:

Total
Bookmark1
Bookmark2
Bookmark3


If you can use an extra line of code, you could do it like this:

for bkmk in arcpy.mapping.ListBookmarks(mxd,"*",df):
    if bkmk.name in ["Bookmark1","Bookmark3"]:
        print bkmk.name


results in:

Bookmark1
Bookmark3



If it has to be on one line, you could use some list comprehension:

for bkmk in [bkmk for bkmk in arcpy.mapping.ListBookmarks(mxd,"*",df) if bkmk.name in ["Bookmark1","Bookmark3"]]:
    print bkmk.name


Kind regards,

Xander
0 Kudos
DannyLackey
Deactivated User
Hi Danny,

Suppose when I use the following code:

for bkmk in arcpy.mapping.ListBookmarks(mxd,"*",df):
    print bkmk.name


I get this result:

Total
Bookmark1
Bookmark2
Bookmark3


If you can use an extra line of code, you could do it like this:

for bkmk in arcpy.mapping.ListBookmarks(mxd,"*",df):
    if bkmk.name in ["Bookmark1","Bookmark3"]:
        print bkmk.name


results in:

Bookmark1
Bookmark3



If it has to be on one line, you could use some list comprehension:

for bkmk in [bkmk for bkmk in arcpy.mapping.ListBookmarks(mxd,"*",df) if bkmk.name in ["Bookmark1","Bookmark3"]]:
    print bkmk.name


Kind regards,

Xander


This might be the solution I've been looking for.  I'll give it a shot and report back.  Thank you!

EDIT:  Yes, this worked like a charm.  Thank you!
0 Kudos