<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Zoom/Pan to layer using Arcpy in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/zoom-pan-to-layer-using-arcpy/m-p/62369#M5024</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Im not sure how helpful this code will be. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I use it to get the extents of grid features and zoom to those extents. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;the line value in df.extent can be multiplied as well if you want to zoom out say 10% &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;you can do df.extent= newExtent * 1.1&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import arcpy
from arcpy import env
from arcpy import mapping
env.workspace = r"C:\Users\atimpson\Desktop\Grid"

mxd = mapping.MapDocument("Current")

fc = "GRID"
count = str(arcpy.GetCount_management(fc))

x = 0

while x &amp;lt; int(count):
&amp;nbsp;&amp;nbsp;&amp;nbsp; rows = arcpy.SearchCursor(fc, "PageNumber = " + str(x))
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; xmin, ymin, xmax, ymax&amp;nbsp; = row.shape.extent.XMin, row.shape.extent.YMin, row.shape.extent.XMax, row.shape.extent.YMax
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; df = arcpy.mapping.ListDataFrames(mxd)[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; newExtent = df.extent
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; newExtent.XMin, newExtent.YMin, newExtent.XMax, newExtent.YMax = xmin, ymin, xmax, ymax
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; df.extent = newExtent
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.RefreshActiveView()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mapping.ExportToJPEG(mxd, r"C:\Users\atimpson\Desktop\Grid\JPEG_" + str(x) + ".jpg", df, df_export_width=1728, df_export_height=948, world_file=True)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print('Exported image' )
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print(x, 'of', count)
&amp;nbsp;&amp;nbsp;&amp;nbsp; x += 1

print("Export Complete")

&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 10 Dec 2021 22:23:12 GMT</pubDate>
    <dc:creator>AnthonyTimpson2</dc:creator>
    <dc:date>2021-12-10T22:23:12Z</dc:date>
    <item>
      <title>Zoom/Pan to layer using Arcpy</title>
      <link>https://community.esri.com/t5/python-questions/zoom-pan-to-layer-using-arcpy/m-p/62368#M5023</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;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.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you in advance&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Claudine&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; import os.path &amp;nbsp;&amp;nbsp;&amp;nbsp; import arcpy&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; mxd = arcpy.mapping.MapDocument("CURRENT") &amp;nbsp;&amp;nbsp;&amp;nbsp; dirPath = os.path.dirname(mxd.filePath) &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.env.overwriteOutput = True&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0] &amp;nbsp;&amp;nbsp;&amp;nbsp; tocLayer = arcpy.mapping.ListLayers(mxd, "Buffer Layers", df)[0] &amp;nbsp;&amp;nbsp;&amp;nbsp; project = arcpy.GetParameterAsText(0) &amp;nbsp;&amp;nbsp;&amp;nbsp; buffer_shp = dirPath + "\\buffer.shp"&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Buffer_analysis(project, buffer_shp, "2 Miles", "FULL", "ROUND", "ALL", "")&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; twoMileBuffer_shp = arcpy.mapping.Layer(buffer_shp) &amp;nbsp;&amp;nbsp;&amp;nbsp; twoMileBuffer_shp.name = "Two Mile Buffer" &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.AddLayerToGroup(df, tocLayer, twoMileBuffer_shp, "AUTO_ARRANGE")&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 10 Oct 2012 15:37:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/zoom-pan-to-layer-using-arcpy/m-p/62368#M5023</guid>
      <dc:creator>ClaudineSicker</dc:creator>
      <dc:date>2012-10-10T15:37:32Z</dc:date>
    </item>
    <item>
      <title>Re: Zoom/Pan to layer using Arcpy</title>
      <link>https://community.esri.com/t5/python-questions/zoom-pan-to-layer-using-arcpy/m-p/62369#M5024</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Im not sure how helpful this code will be. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I use it to get the extents of grid features and zoom to those extents. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;the line value in df.extent can be multiplied as well if you want to zoom out say 10% &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;you can do df.extent= newExtent * 1.1&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import arcpy
from arcpy import env
from arcpy import mapping
env.workspace = r"C:\Users\atimpson\Desktop\Grid"

mxd = mapping.MapDocument("Current")

fc = "GRID"
count = str(arcpy.GetCount_management(fc))

x = 0

while x &amp;lt; int(count):
&amp;nbsp;&amp;nbsp;&amp;nbsp; rows = arcpy.SearchCursor(fc, "PageNumber = " + str(x))
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; xmin, ymin, xmax, ymax&amp;nbsp; = row.shape.extent.XMin, row.shape.extent.YMin, row.shape.extent.XMax, row.shape.extent.YMax
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; df = arcpy.mapping.ListDataFrames(mxd)[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; newExtent = df.extent
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; newExtent.XMin, newExtent.YMin, newExtent.XMax, newExtent.YMax = xmin, ymin, xmax, ymax
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; df.extent = newExtent
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.RefreshActiveView()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mapping.ExportToJPEG(mxd, r"C:\Users\atimpson\Desktop\Grid\JPEG_" + str(x) + ".jpg", df, df_export_width=1728, df_export_height=948, world_file=True)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print('Exported image' )
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print(x, 'of', count)
&amp;nbsp;&amp;nbsp;&amp;nbsp; x += 1

print("Export Complete")

&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 22:23:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/zoom-pan-to-layer-using-arcpy/m-p/62369#M5024</guid>
      <dc:creator>AnthonyTimpson2</dc:creator>
      <dc:date>2021-12-10T22:23:12Z</dc:date>
    </item>
    <item>
      <title>Re: Zoom/Pan to layer using Arcpy</title>
      <link>https://community.esri.com/t5/python-questions/zoom-pan-to-layer-using-arcpy/m-p/62370#M5025</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I finally figured it out and of course it was easier than I originally made it.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I just put this after the code referenced above:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;lyr=arcpy.mapping.ListLayers(mxd, "Two Mile Buffer", df)[0] df.extent = lyr.getExtent(True) arcpy.RefreshActiveView()&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 10 Oct 2012 17:31:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/zoom-pan-to-layer-using-arcpy/m-p/62370#M5025</guid>
      <dc:creator>ClaudineSicker</dc:creator>
      <dc:date>2012-10-10T17:31:09Z</dc:date>
    </item>
  </channel>
</rss>

