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.
John
Solved! Go to Solution.
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 = arcpy.mp.ArcGISProject(r"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]
mf.camera.setExtent(mf.getLayerExtent(lyr, False, True))
aprx.saveACopy(r"C:\Projects\YosemiteNP\Yosemite_Updated.aprx")
del aprx
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 = arcpy.mp.ArcGISProject(r"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]
mf.camera.setExtent(mf.getLayerExtent(lyr, False, True))
aprx.saveACopy(r"C:\Projects\YosemiteNP\Yosemite_Updated.aprx")
del aprx
David,
I have tried this method, it does update the extent on the screen. But CreateTilePackage does not use this extent or respect the extent in the environment. It only seems to use the extent as set as a property of the map. You see this in the UX by double clicking the "map" in the Content panel-> Extent.
Thanks.
Hi @JohnFix1 ,
Did you ever find a solution/workaround to the problem you were facing. I am stuck at the same stage where CreateVectorTilePackage doesn't seem to respect the extent of a mapview screen.
Jaivik Pathak