ArcGIS Pro: Set a Map's extent from a layer's extent via Python

12-01-2020 01:01 PM
Labels (1)
New Contributor III

in ArcGIS Pro 2.6.2 I have a map named "VTPK Output" and I want to set the map's extent to the extent of a layer called "PACKAGE_AREA" in a python script. There are other maps in my project.

The layer has a definition query that is set to a particular area. I will then change the query and run my script for another area, but it needs to set the map extent property. As you can image, the script is creating a vector tile cache.

I've written some python scripts, but I'm between novice and rookie....

Thanks for your help in advance.


0 Kudos
1 Reply
MVP Regular Contributor

I'm a rookie myself with ArcGIS Pro, but I think this is done with a 'camera' object.
I think there's a good example/code sample here - Camera—ArcGIS Pro | Documentation

this is 'camera sample 1':

import arcpy
aprx ="C:\Projects\YosemiteNP\Yosemite.aprx")

m = aprx.listMaps("Yose*")[0]
lyr = m.listLayers("Ranger Stations")[0]
lyt = aprx.listLayouts("Main Attr*")[0]
mf = lyt.listElements("mapframe_element", "Yosemite National Park")[0], False, True))

del aprx