Quick & Dirty arcpy: Autopan ArcMap using arcpy
Question: How do I get ArcMap to automatically pan through an area.
As I mentioned in a previous post, I recently had the need to have ArcMap automatically pan through a project area. My first attempt was to print a series of data-driven pages (using a fishnet polygon layer as the index) this but that did not accomplish what I needed so I switched to arcpy, which made the task simple enough. Nothing special or tricky about this code, but just did not find it anywhere else.
The one thing to note is that I have a 1 second pause between pans–this was to allow image tiles to download. You will need to adjust the delay to meet your needs. The toolbox and code can also be downloaded.
import sys,arcpy,datetime
inLayer = sys.argv[1]
def printit(inMessage):
print inMessage
arcpy.AddMessage(inMessage)
mxd = arcpy.mapping.MapDocument("CURRENT")
arcpy.MakeFeatureLayer_management(inLayer, "indexLayer")
cur=arcpy.SearchCursor("indexLayer")
df = arcpy.mapping.ListDataFrames(mxd)[0]
newExtent = df.extent
iCount = 0
iTotal = (arcpy.GetCount_management("indexLayer").getOutput(0))
for row in cur:
thisPoly = row.getValue("Shape")
newExtent.XMin, newExtent.YMin = thisPoly.extent.XMin, thisPoly.extent.YMin
newExtent.XMax, newExtent.YMax = thisPoly.extent.XMax, thisPoly.extent.YMax
df.extent = newExtent
time.sleep(1)
iCount+=1
printit("Panned to feature {0} of {1}".format(iCount,iTotal))
del row
del cur