AnsweredAssumed Answered

Zoom/Pan to layer using Arcpy

Question asked by claudines on Oct 10, 2012
Latest reply on Oct 10, 2012 by claudines
I have the following script to be used inside ArcMap 10.1. It prompts the user for a shape file, creates a 2 mile buffer around it and then puts the buffered shapefile into a layer group. I want to then zoom to the buffer file. I tried to use pan to selected but since since I do not really have the buffer file selected, it is not working. Anybody know how to zoom/pan to a layer using python? Below is what I have working so far. I just need the code to zoom/pan to the extents of the "Two Mile Buffer" layer. 

Thank you in advance

Claudine

    import os.path     import arcpy      mxd = arcpy.mapping.MapDocument("CURRENT")     dirPath = os.path.dirname(mxd.filePath)     arcpy.env.overwriteOutput = True      df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]     tocLayer = arcpy.mapping.ListLayers(mxd, "Buffer Layers", df)[0]     project = arcpy.GetParameterAsText(0)     buffer_shp = dirPath + "\\buffer.shp"      arcpy.Buffer_analysis(project, buffer_shp, "2 Miles", "FULL", "ROUND", "ALL", "")      twoMileBuffer_shp = arcpy.mapping.Layer(buffer_shp)     twoMileBuffer_shp.name = "Two Mile Buffer"     arcpy.mapping.AddLayerToGroup(df, tocLayer, twoMileBuffer_shp, "AUTO_ARRANGE")

Outcomes