MartinHvidberg

make Python do Pan/Zoom?

Discussion created by MartinHvidberg on May 20, 2014
Latest reply on May 21, 2014 by xander_bakker
Dear Forum

I need to make a small tool that will automatically Pan and Zoom around in ArcMap.
The overall purpose is to time how long time it takes for the screen to redraw after each Pan/Zoom.
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.
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.
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?

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:
    for row in cursor:
        lstOIDs.append(row[0])

# Run through OIDs
arcpy.MakeFeatureLayer_management (strPolygons, "Boxes")
for ID in lstOIDs:
    strSelector = '"OBJECTID" = '+str(ID)
    arcpy.SelectLayerByAttribute_management("Boxes", "NEW_SELECTION", strSelector)
    df.zoomToSelectedFeatures()
    arcpy.RefreshActiveView()

# closing up ...
df.extent = xtnInit
arcpy.RefreshActiveView()


Best regards
Martin

Outcomes