ArcPy – How to Zoom to Selected Feature

arcgis-10.0arcpyselectzoom

Is there a way to zoom to the extent of a selected feature using the ArcPy module in ArcGIS Desktop 10.

Best Answer

I've got a piece of code that works. I found it here on the ESRI website. Add it as a script to a model, then connect the output of a select by attribute tool to it. It does exactly what I want.

import arcpy
mxd = arcpy.mapping.MapDocument('CURRENT')
df = arcpy.mapping.ListDataFrames(mxd, "Layers") [0]
df.zoomToSelectedFeatures()
arcpy.RefreshActiveView()