Set extent to aprx with Python

393
2
10-19-2020 04:55 AM
ModyBuchbinder
Regular Contributor II

Hi all

I have an aprx with one map and one layer.

I want to change the extent of the aprx with Python so when the user open the aprx the extent will be full extent (it was save with wrong extent.

I tried the very simple code below, it does not gives an error and the aprx is saved but the extent is unchanged.

When I uncomment the zoomToAllLayers I get an error.

There is some solutions with layout (I do not have it in this aprx).

If I work with the CURRENT aprx then the activeView give me mapView that is working but I do want it to run without open the aprx.

Any ideas?

import arcpy
aprx = arcpy.mp.ArcGISProject(r"xx.aprx")
map1 = aprx.listMaps()[0]
mapView = map1.defaultView
lyr = map1.listLayers()[0]
desc = arcpy.Describe(lyr)
print ( str(desc.extent))
mapView.camera.setExtent(desc.extent)
#mapView.zoomToAllLayers()
aprx.save()
2 Replies
RyanKelley3
New Contributor III

ever figure this out?

0 Kudos
mody_buchbinder
New Contributor III

No. I could not find any way to change any other aprx but the CURRENT one.

I found a few other methods in arcpy.mp that works only on the current aprx so I think it is a limitation.