import os.path import arcpy mxd = arcpy.mapping.MapDocument("CURRENT") dirPath = os.path.dirname(mxd.filePath) arcpy.env.overwriteOutput = True df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0] tocLayer = arcpy.mapping.ListLayers(mxd, "Buffer Layers", df)[0] project = arcpy.GetParameterAsText(0) buffer_shp = dirPath + "\\buffer.shp" arcpy.Buffer_analysis(project, buffer_shp, "2 Miles", "FULL", "ROUND", "ALL", "") twoMileBuffer_shp = arcpy.mapping.Layer(buffer_shp) twoMileBuffer_shp.name = "Two Mile Buffer" arcpy.mapping.AddLayerToGroup(df, tocLayer, twoMileBuffer_shp, "AUTO_ARRANGE")
Solved! Go to Solution.
lyr=arcpy.mapping.ListLayers(mxd, "Two Mile Buffer", df)[0] df.extent = lyr.getExtent(True) arcpy.RefreshActiveView()
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 < int(count):
rows = arcpy.SearchCursor(fc, "PageNumber = " + str(x))
for row in rows:
xmin, ymin, xmax, ymax = row.shape.extent.XMin, row.shape.extent.YMin, row.shape.extent.XMax, row.shape.extent.YMax
df = arcpy.mapping.ListDataFrames(mxd)[0]
newExtent = df.extent
newExtent.XMin, newExtent.YMin, newExtent.XMax, newExtent.YMax = xmin, ymin, xmax, ymax
df.extent = newExtent
arcpy.RefreshActiveView()
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)
print('Exported image' )
print(x, 'of', count)
x += 1
print("Export Complete")
lyr=arcpy.mapping.ListLayers(mxd, "Two Mile Buffer", df)[0] df.extent = lyr.getExtent(True) arcpy.RefreshActiveView()