We have an old python script that zooms to the extent of the layers selected in the dataframe. We are trying to update it for Pro and was hoping someone could point us in the right direction.
import arcpy
MXD=arcpy.mapping.MapDocument('current')
dataframe = arcpy.mapping.ListDataFrames(MXD, "Layers")[0]
dataframe.zoomToSelectedFeatures()
arcpy.RefreshActiveView()
Solved! Go to Solution.
Although the name is zoomToAllLayers, the documentation shows there is a selection_only parameter. The ArcMap script using dataframe.zoomToSelectedFeatures is not layer specific so all selected features across all layers determine the extent, which is the same as zoomToAllLayers.
@JoshuaBixby ahhhh I see that now. Thanks to your help I was able to update the script!
import arcpy
aprx = arcpy.mp.ArcGISProject("CURRENT")
dataframe = aprx.activeView
dataframe.zoomToAllLayers(True)
Have you tried anything yet? Which part of translating arcpy.mapping code to arcpy.mp are you stuck on? I would start with Migrating from arcpy.mapping to ArcGIS Pro - ArcGIS Pro | Documentation, it has good code examples to at least get you to opening a specific map.
@JoshuaBixby The part I am stuck on is "zoomToSelectedFeatures()" I cannot find the arcpy,mp equivalent.
zoomToAllLayers in MapView—ArcGIS Pro | Documentation
@JoshuaBixbyI don't want to zoom to all layers. I want to zoom to the selected features within a layer. Example: Parcel is selected then you right click "Zoom to Selection"
Although the name is zoomToAllLayers, the documentation shows there is a selection_only parameter. The ArcMap script using dataframe.zoomToSelectedFeatures is not layer specific so all selected features across all layers determine the extent, which is the same as zoomToAllLayers.
@JoshuaBixby ahhhh I see that now. Thanks to your help I was able to update the script!
import arcpy
aprx = arcpy.mp.ArcGISProject("CURRENT")
dataframe = aprx.activeView
dataframe.zoomToAllLayers(True)