Getting current map frame extent without having to save the project each time?

05-03-2021 12:43 PM
Occasional Contributor III

I can get a map's view extent by doing this:

m = p.listMaps()[0]
e = m.defaultCamera.getExtent()


However this is real janky because a user can move the map and re-run the code, and it doesn't update until the project is saved.  This has been the case from what I can tell, for around five years now.


Maybe it's easier to explain what I need to do.  In a script tool, I need to set the arcpy.env.extent parameter to "Same as display" but do it with python rather than forcing a user to manually select "same as display" in the GUI every single time.


Is there a "best practice" to implement this behavior in python?  I had read that this property was made available to python sometime recently, but I can't find any documentation on it.

Tags (2)
0 Kudos
1 Reply
MVP Esteemed Contributor  # and there is getExtent

It think that this is full circle and the setExtent and getExtent were added in recent versions of Pro.

I don't know how otherwise you would implement this in a python script other than grabbing this parameter after the script is actually run

... sort of retired...