1

I have an MXD with two data frames. I want to use Data Driven Pages (DDP) to export this to PDF but have the second of the data frames be one extent ahead. I have the following script to export the two frames with the same extent using DDP. I want to have frame2 be one ahead of the DDP page of the master frame.

Any ideas?

#set map document
mxd = arcpy.mapping.MapDocument("CURRENT")

#set master data frame - dataframe with DDP already applied
masterFrame = arcpy.mapping.ListDataFrames(mxd)

#set second data frame to copy master
frame2 = arcpy.mapping.ListDataFrames(mxd,"New Data Frame")

#for loop to process DDP using number of pages
for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1):
   mxd.dataDrivenPages.currentPageID = pageNum

   #this sets the extent to be the same but I want frame2 to be one ahead, if that makes sense?
   frame2[0].extent = masterFrame[0].extent
   arcpy.mapping.ExportToPDF(mxd, r"C:\Users\user\Desktop\pdffolder\"+ str(pageNum) + '.pdf')
  • I have played around with the DDP Tools, but I am also still learning. I was just wondering if this line: masterFrame = arcpy.mapping.ListDataFrames(mxd) should not also name the "Master Dataframe" something like "masterFrame = arcpy.mapping.ListDataFrames(mxd, "Main")" or perhaps "masterFrame = arcpy.mapping.ListDataFrames(mxd)[0]" – Keagan Allan Feb 14 at 0:01
  • As an aside...could you please edit your question to include the outcomes of running the above script? – Keagan Allan Feb 14 at 0:08
  • @KeaganAllan what this code does is move two data frames to the same extent and export them based on the DDP. I want them to be different extents, like two DDP, one for each data frame. – Eric.18 Feb 14 at 16:34
0

Here is something that works for me. Let me know if it is what you are looking for. I have put some comments to explain what I did.

import os
import arcpy
from arcpy import mapping

#set second data frame to copy master

#set map document
mxd = arcpy.mapping.MapDocument("CURRENT")
#set master data frame - dataframe with DDP already applied
masterFrame = arcpy.mapping.ListDataFrames(mxd)[0]
Frame2 = arcpy.mapping.ListDataFrames(mxd)[1]

print  mxd.dataDrivenPages.pageCount
#for loop to process DDP using number of pages
#I changed your script here to not run to the last page (it would give an error
#if you tried to set Extent 2 to a page that doesn't exist. This gives you an export
# set of P1,P2 ; P2,P3 ; P4,P5 if there are 5 pages.
for pageNum in range(1, mxd.dataDrivenPages.pageCount):
    #I have set the Master Dataframe to have the extent of the PageId + 1 (one page ahead)
    mxd.dataDrivenPages.currentPageID = pageNum + 1
    #I set Frame 2 to have the same extent as the Master
    Frame2.extent = masterFrame.extent
    #I reset the extent of the Master back to the correct page...then export.
    mxd.dataDrivenPages.currentPageID = pageNum
    print pageNum

    OutF = os.path.join("C:/temp" ,str(pageNum) + ".pdf" )
    arcpy.mapping.ExportToPDF(mxd, OutF)
  • Okay. I modified your code to best fit my issues. I had to add Frame2.scale = masterFrame.scale and Frame2.rotation = masterFrame.rotation within the for loop after setting the extent and it looks to have worked. I greatly appreciate your feedback and help on this. – Eric.18 Feb 15 at 15:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.