[915] Implementation of zooming to layer and exporting to PDF in arcpy

发布时间 2023-10-20 09:52:32作者: McDelfino

ref: Camera - ArcGIS Pro

ref: Introduction to arcpy.mp


# Set the path to your project file (.aprx)
project_file = r"Map 1.3 Heritage.aprx"

# Reference the project
aprx = arcpy.mp.ArcGISProject(project_file)

# get the sitebuffer layer
m = aprx.listMaps()[0]
lyr = m.listLayers()[3]

# get the Map element of the layout
lyt = aprx.listLayouts()[0]
mf = lyt.listElements()[-1]

# set the extent to the sitebuffer layer's extent
mf.camera.setExtent(mf.getLayerExtent(lyr, False, True))

# export to PDF
lyt.exportToPDF(lyt.name)
    
del aprx