import arcpy
mxd = arcpy.mapping.MapDocument('CURRENT')
df = arcpy.mapping.ListDataFrames(mxd, "Layers") [0]
df.zoomToSelectedFeatures()
Obviously you'd have to modify the code to include your custom
selection. More discussion can be found in this thread on the ESRI
forums:
http://forums.arcgis.com/threads/7703-Adding-Zoom-to-Selected-feature-to-execute-at-the-end-of-model.
arcpy.AddMessage(
"beginning layer filter of data frame" + df.name)arcpy.AddMessage(defQry)
lyr = arcpy.mapping.ListLayers(obj.mxd,
"Tantalis Files", df)[0]arcpy.AddMessage(lyr.name)
arcpy.AddMessage(
"defined the lyr for Tantalis Files?") # ARGH! REMEMBER TO CLEAR DEFINITION QUERY FIRST # otherwise there'll be nothing to query if it's the 2nd time !lyr.definitionQuery =
"" # Do selection and zoom inarcpy.SelectLayerByAttribute_management(lyr,
"CLEAR_SELECTION")arcpy.SelectLayerByAttribute_management(lyr,
"NEW_SELECTION", defQry)obj.SelectedSetChecker(lyr)
# check for no polys or zero areadf.zoomToSelectedFeatures()
arcpy.AddMessage(
"zoomed to my selected feature! ")arcpy.SelectLayerByAttribute_management(lyr,
"CLEAR_SELECTION")lyr.definitionQuery = defQry
# filter the layer to just the ones you want # main map, tiny polygon, and no inset, then zoom out if df.name == "Layers" and df.scale < 10000 and insetmap <> "None":df.scale =
10000 else: # otherwise do the scale rounding as per routinedf.scale = obj.scalefixer(df.scale)