Select to view content in your preferred language

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

2851
4
Jump to solution
12-01-2020 01:01 PM
JohnFix1
Regular Contributor

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

0 Kudos
1 Solution

Accepted Solutions
DavidPike
MVP Frequent 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 = 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

 

View solution in original post

Tags (3)
4 Replies
DavidPike
MVP Frequent 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 = 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

 

Tags (3)
JohnFix1
Regular Contributor

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.

0 Kudos
Jaivik_P
Occasional Contributor

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

0 Kudos
JohnFix1
Regular Contributor

No, I have not. I'm now at ArcGIS Pro 3.4 and thought perhaps a solution would be at this version. But I have not found one yet.

Any luck on your end?

0 Kudos