Select to view content in your preferred language

Map automation - specific to my organisation

332
0
06-22-2022 04:26 AM
MichaelFowler1
New Contributor III

Hi All!

I'm currently working on a script that can automate basic map production for my organisation.

The current part I'm stuck on is, I have bookmarks that the user can select from a pre-defined list, although if the area they want to look at isn't in that list they could enter the extent themselves and set the scale. Although, currently if they select a bookmark and leave the extent part blank it throws an error as nothing has been entered for extent even though I have set it to be an optional parameter. 

Is there a way I can calculate the extent if the user selects a bookmark so they can be in the same tool, while allowing the user to manually enter the extent if needed?

Below is my current code:

 

import arcpy
arcpy.env.overwriteOutput = True
workspace = arcpy.GetParameterAsText(0)
aprx = arcpy.mp.ArcGISProject('CURRENT')
lyt = aprx.listLayouts(Product_Size)[0]
aprxMap = aprx.listMaps('Map')[0]
mf = lyt.listElements('MAPFRAME_ELEMENT', 'Map Frame')[0]
in_bookmark = arcpy.GetParameterAsText(1)
bookmark = mf.map.listBookmarks()
# Loop to zoom if user selects bookmark
for bkmk in bookmark:
    if bkmk.name == in_bookmark:
        mf.zoomToBookmark(bkmk) 
        arcpy.AddMessage(f'{in_bookmark} bookmark set')        
    else:
        continue
extent = arcpy.GetParameterAsText(2)
arcpy.env.extent = extent
mf.camera.setExtent(arcpy.env.extent)

 

I think my issue is I'm still not understanding how exactly extent works in arcpy, but reading the documentation hasn't been much help so far. I would really appreciate some help or a nice gentle nudge in the right direction. If more of the overall code would be useful to see, let me know!

Thank you!

0 Kudos
0 Replies