arcGIS Pro Extents in the Viewing Pane

01-12-2017 08:50 AM
New Contributor II


How do I get the extents that are visible in the viewing pane. In old arcpy it would've been:

  1. import arcpy  
  2. import arcpy.mapping  
  5. ## Sets the MXD file  
  6. IMXD = arcpy.mapping.MapDocument("CURRENT")  
  7. ## Sets the Dataframe  
  8. DF = arcpy.mapping.ListDataFrames(IMXD, "Layers")[0]  
  10. print DF.extent  

Any help greatly appreciated.


#data frame extent#graphics extentknowni_coop

0 Kudos
5 Replies
MVP Esteemed Contributor

Something along the lines of:

map_name = # name of map to get extent object
aprx ="CURRENT")
mp = aprx.listMaps(map_name)[0]
ext = mp.defaultCamera.getExtent()

If you are interested in layouts instead of maps, there is a listLayouts() method to call.

0 Kudos
New Contributor II

Cheers Joshua,

I've found that saving the .aprx before the rest of the above code is essential as it seems to define where the "camera's" location.


0 Kudos
MVP Esteemed Contributor

I will have to take a closer look at that behavior.  There either might be different code that doesn't require the APRX to be saved first, or possibly it is a bug.

0 Kudos
MVP Regular Contributor


    This issue of having to save the project in order to get the current map view extents is almost three years old.  Are there any plans to fix this?

aprx ="CURRENT")

This does not work for this either, you have to physically save the map first.

Joshua Bixby

Also if I move around in the Map View and then switch to the Layout View and I physically click to save the project the script to get the Map View extents does not work.  If I physically click save in the Map View the script will work. 

Here is the entire script.

arcpy.env.overwriteOutput = True

# Use the current arcgis pro project
aprx ="CURRENT")

# List the map
m = aprx.listMaps("Layers")[0] # this is not saving the project????
layout = aprx.listLayouts("Template_8_5x11_Layout")[0]
frame = layout.listElements("MAPFRAME_ELEMENT")[0]
ext = m.defaultCamera.getExtent()

increment = 300
currenscale = int( + 300
#arcpy.AddMessage("current " + str(currenscale))
newscale = currenscale - (currenscale % increment)
#arcpy.AddMessage("NEW " + str(newscale)) = newscale
0 Kudos
Regular Contributor II


# zoom to selected features
import arcpy
m = p.listMaps()[0]
mv = p.activeView
# part of trail selected
lay = m.listLayers('trail')[0]
extent = mv.getLayerExtent(lay, True, True)


Maybe this function was not available in 2017, but it is now in 2021 in version 2.8 or earlier.

The trick is to realise that the extents are available in the MapView of the active Map. While looking for this I tried out using Bookmarks which are also available, maybe a nice way to store the extent of selections.

0 Kudos