I'm trying to automate some tasks for unit test. Once of these tasks is zooming into a map a fixed amount and forcing ArcMap to redraw at the new extent. The Data Frame is named Raster Data Sets.
The display is refreshing but it does not appear to honor the panToExtent() method. The AddMessage command shows that the value for the extent class was changed as expected.
ideas?
import arcpy
zoomScale=arcpy.GetParameterAsText(0)
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd, "Raster Data Sets")[0]
lyr = arcpy.mapping.ListLayers(mxd, 'County Boundaries*', df)[0]
ext = lyr.getExtent()
arcpy.AddMessage("Old xmin, ymin, xmax, ymax: " + str(ext.XMin) + ", " + str(ext.YMin) + ", " + str(ext.XMax) + ", " + str(ext.YMax))
# change extent
temp = ext.XMin + float(zoomScale)
ext.XMin = temp
temp = ext.YMin + float(zoomScale)
ext.YMin = temp
temp = ext.XMax - float(zoomScale)
ext.XMax = temp
temp = ext.YMax - float(zoomScale)
ext.YMax = temp
arcpy.AddMessage("New xmin, ymin, xmax, ymax: " + str(ext.XMin) + ", " + str(ext.YMin) + ", " + str(ext.XMax) + ", " + str(ext.YMax))
df.panToExtent(ext)
arcpy.RefreshActiveView()
sys.argv[2]=True
arcpy.SetParameter(1,"True")
So it doesn't recenter?
Pans and centers the MapFrame using a new Extent object without changing the map frame's scale.
It redraws but it does not appear to be resulting in the desired behavior (zoom into the new map extent).
you might have a weird combo of extents... give
zoomToAllLayers ({selection_only}, {symbolized_extent})
from http://pro.arcgis.com/en/pro-app/arcpy/mapping/mapframe-class.htm
there is an equivalent for arcmap's arcpy mapping module