HOW TO

Use and export Data Driven Pages in a map document with multiple data frames

Last Published: July 11, 2020

Summary

Data Driven Pages require the use of an index layer to determine the extent of the data frame for each page. The index layer can be any layer on the map used to define the extent, depending on the feature layers. The functionality of Data Driven pages can be enhanced further to enable export and use in a map document containing multiple data frames using the arcpy.mapping module.

This article provides steps to use and export Data Driven Pages with multiple data frames.

Procedure

  1. Import the necessary modules.
import os
import arcpy
from arcpy import mapping
  1. Specify the map document containing the layers and the data frames.
mxd = arcpy.mapping.MapDocument("CURRENT")
masterFrame = arcpy.mapping.ListDataFrames(mxd)[0]
Frame2 = arcpy.mapping.ListDataFrames(mxd)[1]
Frame3 = arcpy.mapping.ListDataFrames(mxd)[2]
  1. Print the page count.
print mxd.dataDrivenPages.pageCount
  1. Create a loop to go over all the available frames and export the page to a desired location. The code segment also sets the extent of the frames to the master frame extent.
for pageNum in range(1, mxd.dataDrivenPages.pageCount):
    mxd.dataDrivenPages.currentPageID = pageNum + 1
    Frame2.extent = masterFrame.extent
    Frame3.extent = masterFrame.extent	
    
    mxd.dataDrivenPages.currentPageID = pageNum
    print pageNum

    OutF = os.path.join("<folder_location>" ,str(pageNum) + ".pdf" )
    arcpy.mapping.ExportToPDF(mxd, OutF)
Note:
Since the frame extent is set to copy the master extent, the data must be available in the same range on the map for the data frame to be visible.

The following shows the full code:

import os
import arcpy
from arcpy import mapping

mxd = arcpy.mapping.MapDocument("CURRENT")

masterFrame = arcpy.mapping.ListDataFrames(mxd)[0]
Frame2 = arcpy.mapping.ListDataFrames(mxd)[1]
Frame3 = arcpy.mapping.ListDataFrames(mxd)[2]

print  mxd.dataDrivenPages.pageCount

for pageNum in range(1, mxd.dataDrivenPages.pageCount):
    mxd.dataDrivenPages.currentPageID = pageNum + 1
    Frame2.extent = masterFrame.extent
    Frame3.extent = masterFrame.extent
    
    mxd.dataDrivenPages.currentPageID = pageNum
    print pageNum

    OutF = os.path.join("C:/temp" ,str(pageNum) + ".pdf" )
    arcpy.mapping.ExportToPDF(mxd, OutF)

Article ID:000022852

Software:
  • ArcMap

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options

Related Information

Discover more on this topic