Hi all!
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.
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).
I have looked at all the ArcGIS Pro documentation and none of it has helped so far.
Any help would be greatly appreciated!
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()
Solved! Go to Solution.
There are two issues.
# 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')
There are two issues.
# 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')
Thank you that works perfectly!