<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Arcpy - user selecting a bookmark in Geoprocessing Questions</title>
    <link>https://community.esri.com/t5/geoprocessing-questions/arcpy-user-selecting-a-bookmark/m-p/1180576#M26358</link>
    <description>&lt;P&gt;Hi all!&lt;/P&gt;&lt;P&gt;I'm trying to create a script that will automatically create a map after a few user inputs. The map template I'm using will have all bookmarks predefined and the end user will just need to select the one they want from the drop down.&lt;/P&gt;&lt;P&gt;The below code is what i have tried so far, although the output is always 'South China Sea' as that is the last bookmark in my pre-defined list (in the toolbox).&lt;/P&gt;&lt;P&gt;I have looked at all the ArcGIS Pro documentation and none of it has helped so far.&lt;/P&gt;&lt;P&gt;Any help would be greatly appreciated!&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
workspace = arcpy.GetParameterAsText(0)
productName = arcpy.GetParameterAsText(1)
aprx = arcpy.mp.ArcGISProject('CURRENT')
lyt = aprx.listLayouts()[0]
aprxMap = aprx.listMaps('Map')[0]
mf = lyt.listElements('MAPFRAME_ELEMENT', 'Map Frame')[0]
bookmark = arcpy.GetParameterAsText(2)
bookmark = mf.map.listBookmarks()
for bkmk in bookmark: # loop through all bookmarks until find specific bookmark
    if bkmk.name == 'Australia': 
        mf.zoomToBookmark(bkmk) 
        arcpy.AddMessage('Australia bookmark set')
        # then do layers on/off
    elif bkmk.name == 'Papua New Guinea': 
        mf.zoomToBookmark(bkmk) # zoom to Australia
        arcpy.AddMessage('Papua New Guinea bookmark set')
        # then do layers on/off
    elif bkmk.name == 'Indonesia': 
        mf.zoomToBookmark(bkmk) 
        arcpy.AddMessage('Indonesia bookmark set')
        # then do layers on/off
    elif bkmk.name == 'South China Sea': 
        mf.zoomToBookmark(bkmk) 
        arcpy.AddMessage('South China Sea bookmark set')
        # then do layers on/off
    else:
        arcpy.AddWarning('Bookmark does not exist')
out_pdf = (workspace + f'\\Output\\{productName}')
lyt.exportToPDF(out_pdf)
aprx.save()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 07 Jun 2022 13:14:17 GMT</pubDate>
    <dc:creator>MichaelFowler1</dc:creator>
    <dc:date>2022-06-07T13:14:17Z</dc:date>
    <item>
      <title>Arcpy - user selecting a bookmark</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/arcpy-user-selecting-a-bookmark/m-p/1180576#M26358</link>
      <description>&lt;P&gt;Hi all!&lt;/P&gt;&lt;P&gt;I'm trying to create a script that will automatically create a map after a few user inputs. The map template I'm using will have all bookmarks predefined and the end user will just need to select the one they want from the drop down.&lt;/P&gt;&lt;P&gt;The below code is what i have tried so far, although the output is always 'South China Sea' as that is the last bookmark in my pre-defined list (in the toolbox).&lt;/P&gt;&lt;P&gt;I have looked at all the ArcGIS Pro documentation and none of it has helped so far.&lt;/P&gt;&lt;P&gt;Any help would be greatly appreciated!&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
workspace = arcpy.GetParameterAsText(0)
productName = arcpy.GetParameterAsText(1)
aprx = arcpy.mp.ArcGISProject('CURRENT')
lyt = aprx.listLayouts()[0]
aprxMap = aprx.listMaps('Map')[0]
mf = lyt.listElements('MAPFRAME_ELEMENT', 'Map Frame')[0]
bookmark = arcpy.GetParameterAsText(2)
bookmark = mf.map.listBookmarks()
for bkmk in bookmark: # loop through all bookmarks until find specific bookmark
    if bkmk.name == 'Australia': 
        mf.zoomToBookmark(bkmk) 
        arcpy.AddMessage('Australia bookmark set')
        # then do layers on/off
    elif bkmk.name == 'Papua New Guinea': 
        mf.zoomToBookmark(bkmk) # zoom to Australia
        arcpy.AddMessage('Papua New Guinea bookmark set')
        # then do layers on/off
    elif bkmk.name == 'Indonesia': 
        mf.zoomToBookmark(bkmk) 
        arcpy.AddMessage('Indonesia bookmark set')
        # then do layers on/off
    elif bkmk.name == 'South China Sea': 
        mf.zoomToBookmark(bkmk) 
        arcpy.AddMessage('South China Sea bookmark set')
        # then do layers on/off
    else:
        arcpy.AddWarning('Bookmark does not exist')
out_pdf = (workspace + f'\\Output\\{productName}')
lyt.exportToPDF(out_pdf)
aprx.save()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jun 2022 13:14:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/arcpy-user-selecting-a-bookmark/m-p/1180576#M26358</guid>
      <dc:creator>MichaelFowler1</dc:creator>
      <dc:date>2022-06-07T13:14:17Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy - user selecting a bookmark</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/arcpy-user-selecting-a-bookmark/m-p/1182528#M26366</link>
      <description>&lt;P&gt;There are two issues.&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;You have two variables called bookmark. The user input Line8 and list of bookmarks in the map on Line9.&amp;nbsp;Your user input is overwritten by the list of bookmarks.&lt;/LI&gt;&lt;LI&gt;You never compare the&amp;nbsp;bkmk.name in the loop with the user input to find the actual bookmark your are looking for.&lt;/LI&gt;&lt;/OL&gt;&lt;LI-CODE lang="python"&gt;# get the user input bookmark name
in_bookmark = arcpy.GetParameterAsText(2)
bookmark = mf.map.listBookmarks()
for bkmk in bookmark: # loop through all bookmarks until find specific bookmark
    if bkmk.name == in_bookmark: # compare the bookmark name with the user input
        mf.zoomToBookmark(bkmk) 
        arcpy.AddMessage(f'{in_bookmark} bookmark set')
        # then do layers on/off
    else:
        arcpy.AddWarning('Bookmark does not exist')&lt;/LI-CODE&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Tue, 14 Jun 2022 00:09:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/arcpy-user-selecting-a-bookmark/m-p/1182528#M26366</guid>
      <dc:creator>MarkBryant</dc:creator>
      <dc:date>2022-06-14T00:09:18Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy - user selecting a bookmark</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/arcpy-user-selecting-a-bookmark/m-p/1182544#M26367</link>
      <description>&lt;P&gt;Thank you that works perfectly!&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jun 2022 02:37:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/arcpy-user-selecting-a-bookmark/m-p/1182544#M26367</guid>
      <dc:creator>MichaelFowler1</dc:creator>
      <dc:date>2022-06-14T02:37:06Z</dc:date>
    </item>
  </channel>
</rss>

