I am trying to zoom into a selected polygon as part of code for a custom print tool within AppBuilder. Below is my code. However, I am having trouble getting it to zoom into the selected polygon. I have ran into various errors, but the current error is below. Any ideas for resolving this?
Code:
# Part 3: Zoom into selected polygon
aprx = arcpy.mp.ArcGISProject("CURRENT")
# trying to zoom into sltPoly
mv = aprx.activeView # mapview
m = mv.map # map
lay = m.listLayers(sltPoly)
sltLyr = m.listLayers()[3]
for g in m.listLayers():
print("Layer: {0} Layers".format(g.name))
lyrExt = mv.getLayerExtent(sltLyr)
mv.camera.setExtent(lyrExt)
df.scale = 6000
arcpy.SelectLayerByAttribute_management(sltPoly, "CLEAR_SELECTION")
arcpy.Near_analysis(points_lyr, sltPoly)
Error (redacting was my own):
Error executing tool. Export Web Map : Traceback (most recent call last): File "**redacted**\dynamicprintservice\ExportWebMap.py", line 211, in <module> aprx = arcpy.mp.ArcGISProject("CURRENT") File "c:\program files\arcgis\server\framework\runtime\arcgis\Resources\arcpy\arcpy\_mp.py", line 337, in __init__ self._arc_object = arcgisscripting._mapping.ArcGISProject(*gp_fixargs((aprx_path,), True)) OSError: CURRENT Failed to execute (Export Web Map). Failed to execute (Export Web Map).