Extent of map in ArcGIS PRO

6802
10
Jump to solution
03-06-2018 04:39 PM
DavidMatthews3
New Contributor II

In the transition from arcpy.mapping to arcpy.mp there doesn't seem to be a way to get the extent (in order to calculate the center)  of the current map.The camera extent only applies to layouts and MapFrames.

Does anyone know how to get around this?

Something like

aprx=arcpy.mp.ArcGISProject("CURRENT")
mapView = aprx.listMaps()[0]
extent = mapView.extent

Is this possible in pro?

Tags (2)
1 Solution

Accepted Solutions
DavidMatthews3
New Contributor II

After seeing this duplicate question arcGIS Pro Extents in the Viewing Pane  Joshua Bixby which i missed yesterday it seems you need to save the aprx first and use defaultCamera

aprx=arcpy.mp.ArcGISProject("CURRENT")
mapView = aprx.listMaps()[0]
mapExtents=mapView.defaultCamera.getExtent()
mapExtents.lowerLeft

Pan around and save the aprx then

mapExtents=mapView.defaultCamera.getExtent()
mapExtents.lowerLeft

Gives you the current extents (in this case the lower left extents).

Seems like a bug  /missing feature

View solution in original post

10 Replies
DanPatterson_Retired
MVP Emeritus

I haven't had the need to burrow into it yet, but http://pro.arcgis.com/en/pro-app/arcpy/mapping/map-class.htm

cites that it is the mapframe that you are after

Maps are accessed using the listMaps function from the ArcGISProject object and it returns a Python list of Map objects. It is important to uniquely name each map so a specific map can be easily referenced using its name property. A map can also be accessed from a MapFrame object using the map property. Note: arcpy.mp does not provide access to map views within the application; it only provides access to MapFrames.

The mapframe http://pro.arcgis.com/en/pro-app/arcpy/mapping/mapframe-class.htm

DavidMatthews3
New Contributor II

Thanks Dan but it looks like this only works for map frames in layouts. I'm looking for the current extent of the map (what would be  a dataframe in 10.3).

So in 10.3 you might do this

mxd = arcpy.mapping.MapDocument("CURRENT")
df=arcpy.mapping.ListDataFrames(mxd)[0]
extent = df.extent

0 Kudos
DanPatterson_Retired
MVP Emeritus

Everything seems to be associated with the mapframe, even the camera's extent properties as you point out, there has to be a way to step back one step.

0 Kudos
DavidMatthews3
New Contributor II

After seeing this duplicate question arcGIS Pro Extents in the Viewing Pane  Joshua Bixby which i missed yesterday it seems you need to save the aprx first and use defaultCamera

aprx=arcpy.mp.ArcGISProject("CURRENT")
mapView = aprx.listMaps()[0]
mapExtents=mapView.defaultCamera.getExtent()
mapExtents.lowerLeft

Pan around and save the aprx then

mapExtents=mapView.defaultCamera.getExtent()
mapExtents.lowerLeft

Gives you the current extents (in this case the lower left extents).

Seems like a bug  /missing feature

simoxu
by MVP Regular Contributor
MVP Regular Contributor

I tried this code, it didn't work.

Is there an ArcgGIS Idea that we can vote to get this function implemented ASAP?  it's hard to believe this function is missing in the latest version...

0 Kudos
DanPatterson_Retired
MVP Emeritus

ArcGIS Ideas‌ is where you can create an idea

0 Kudos
simoxu
by MVP Regular Contributor
MVP Regular Contributor

Just done it  Please vote it up.

Allow arcpy.mp to change the map extent in ArcGIS Pro 

MattWilkie1
Occasional Contributor II

that link is now "hidden or archived". Searching about hasn't led me to it's new home yet.

0 Kudos
SamMcCants
New Contributor

This worked for me, thank you. One year later, is this still not possible without saving the project? This seems like a big oversight, no?

0 Kudos