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?
Solved! Go to Solution.
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
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
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
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.
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
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...
ArcGIS Ideas is where you can create an idea
Just done it Please vote it up.
that link is now "hidden or archived". Searching about hasn't led me to it's new home yet.
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?