Skip to content

Instantly share code, notes, and snippets.

@cindygis
Created September 1, 2015 09:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cindygis/5e0116bb12f14137848f to your computer and use it in GitHub Desktop.
Save cindygis/5e0116bb12f14137848f to your computer and use it in GitHub Desktop.
Pans and zooms each data frame in an ArcMap document to the extent and scale of the data frame containing the data driven pages index layer before exporting.
#
# @date 25/08/2015
# @author Cindy Williams
#
# Pans and zooms each data frame in an ArcMap document
# to the extent and scale of the data frame containing
# the data driven pages index layer before exporting.
#
# For use as a standalone script.
#
import arcpy
import os
map_doc = r"" # Your mxd here
mxd = arcpy.mapping.MapDocument(map_doc)
out_folder = r"" # Your folder here
if mxd.isDDPenabled: # Check if data driven pages are enabled in the map
ddp = mxd.dataDrivenPages
ddp_df = ddp.dataFrame # Get the data frame containing the data driven pages index layer
# Get all data frames besides the one containing the index layer
dfs = [df for df in arcpy.mapping.ListDataFrames(mxd) if not df.name == ddp_df.name]
# Loop over the data driven pages
for i in range(1, ddp.pageCount + 1):
ddp.currentPageID = i
cur_ddp = ddp.pageRow.getValue(ddp_name)
ddp_jpeg = os.path.join(out_folder, str(cur_ddp) + ".jpg")
for df in dfs:
df.extent = ddp_df.extent
df.scale = ddp_df.scale
arcpy.mapping.ExportToJPEG(mxd, ddp_jpeg, resolution=200)
print("Exported " + ddp_jpeg)
else:
print("Please enable Data Driven Pages before continuing.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment