<?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 make Python do Pan/Zoom? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/make-python-do-pan-zoom/m-p/318502#M24748</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Dear Forum&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I need to make a small tool that will automatically Pan and Zoom around in ArcMap.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The overall purpose is to time how long time it takes for the screen to redraw after each Pan/Zoom.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;First I made a script that jumped from Bookmark to Bookmark, but it didn???t wait for the re-draw to complete, before jumping to the next bookmark ??? I guess this would often be preferable, but in my case it was undesirable behavior.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I have now tried the following code, which opens a feature class (arcpy.GetParameterAsText(0)) that holds 5 polygons. It???s intended to jump to the extent of each of the polygons, in turn. But it seems to jump to some enormous extent many times larger than my entire data extent.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Can any one suggest a good way to make ArcMap jump from place to place, like if you were jumping from bookmark to bookmark, but using Python, and allowing the re-draw to be timed by Python?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
import arcpy

strPolygons = arcpy.GetParameterAsText(0)

# Init
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]
xtnInit = df.extent # remember the original extent

# Build list of OIDs
lstOIDs = list()
with arcpy.da.SearchCursor(strPolygons, ['OID@', 'SHAPE@AREA']) as cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lstOIDs.append(row[0])

# Run through OIDs
arcpy.MakeFeatureLayer_management (strPolygons, "Boxes")
for ID in lstOIDs:
&amp;nbsp;&amp;nbsp;&amp;nbsp; strSelector = '"OBJECTID" = '+str(ID)
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management("Boxes", "NEW_SELECTION", strSelector)
&amp;nbsp;&amp;nbsp;&amp;nbsp; df.zoomToSelectedFeatures()
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.RefreshActiveView()

# closing up ...
df.extent = xtnInit
arcpy.RefreshActiveView()
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Best regards&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Martin&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 20 May 2014 12:41:12 GMT</pubDate>
    <dc:creator>MartinHvidberg</dc:creator>
    <dc:date>2014-05-20T12:41:12Z</dc:date>
    <item>
      <title>make Python do Pan/Zoom?</title>
      <link>https://community.esri.com/t5/python-questions/make-python-do-pan-zoom/m-p/318502#M24748</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Dear Forum&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I need to make a small tool that will automatically Pan and Zoom around in ArcMap.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The overall purpose is to time how long time it takes for the screen to redraw after each Pan/Zoom.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;First I made a script that jumped from Bookmark to Bookmark, but it didn???t wait for the re-draw to complete, before jumping to the next bookmark ??? I guess this would often be preferable, but in my case it was undesirable behavior.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I have now tried the following code, which opens a feature class (arcpy.GetParameterAsText(0)) that holds 5 polygons. It???s intended to jump to the extent of each of the polygons, in turn. But it seems to jump to some enormous extent many times larger than my entire data extent.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Can any one suggest a good way to make ArcMap jump from place to place, like if you were jumping from bookmark to bookmark, but using Python, and allowing the re-draw to be timed by Python?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
import arcpy

strPolygons = arcpy.GetParameterAsText(0)

# Init
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]
xtnInit = df.extent # remember the original extent

# Build list of OIDs
lstOIDs = list()
with arcpy.da.SearchCursor(strPolygons, ['OID@', 'SHAPE@AREA']) as cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lstOIDs.append(row[0])

# Run through OIDs
arcpy.MakeFeatureLayer_management (strPolygons, "Boxes")
for ID in lstOIDs:
&amp;nbsp;&amp;nbsp;&amp;nbsp; strSelector = '"OBJECTID" = '+str(ID)
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management("Boxes", "NEW_SELECTION", strSelector)
&amp;nbsp;&amp;nbsp;&amp;nbsp; df.zoomToSelectedFeatures()
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.RefreshActiveView()

# closing up ...
df.extent = xtnInit
arcpy.RefreshActiveView()
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Best regards&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Martin&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 May 2014 12:41:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/make-python-do-pan-zoom/m-p/318502#M24748</guid>
      <dc:creator>MartinHvidberg</dc:creator>
      <dc:date>2014-05-20T12:41:12Z</dc:date>
    </item>
    <item>
      <title>Re: make Python do Pan/Zoom?</title>
      <link>https://community.esri.com/t5/python-questions/make-python-do-pan-zoom/m-p/318503#M24749</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Martin,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You can directly read the extent of a polygon and assign it to the dataframe extent:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
from datetime import datetime, timedelta

strPolygons = arcpy.GetParameterAsText(0)

# Init
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]
xtnInit = df.extent # remember the original extent

# Build list of SHAPEs
lst_shapes = [row[0] for row in arcpy.da.SearchCursor(strPolygons, ['SHAPE@'])]

# Loop through polygons
lst_drawtimes = []
for shape in lst_shapes:
&amp;nbsp;&amp;nbsp;&amp;nbsp; tm_before = datetime.now()
&amp;nbsp;&amp;nbsp;&amp;nbsp; df.extent = shape.extent
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.RefreshActiveView()
&amp;nbsp;&amp;nbsp;&amp;nbsp; tm_after = datetime.now()
&amp;nbsp;&amp;nbsp;&amp;nbsp; duration = tm_after - tm_before
&amp;nbsp;&amp;nbsp;&amp;nbsp; lst_drawtimes.append(duration)

# closing up ...
df.extent = xtnInit
arcpy.RefreshActiveView()

# list stats
print "Number of draws&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : {0}".format(len(lst_drawtimes))
print "Total time of draws&amp;nbsp; : {0}".format(sum(lst_drawtimes, timedelta()))

if len(lst_drawtimes)&amp;gt; 0:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Average time of draws: {0}".format(sum(lst_drawtimes, timedelta())/len(lst_drawtimes))
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Kind regards,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Xander&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 15:08:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/make-python-do-pan-zoom/m-p/318503#M24749</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2021-12-11T15:08:28Z</dc:date>
    </item>
  </channel>
</rss>

