graphics in data driven pages

129
1
06-03-2011 03:53 PM
Status: Open
Labels (1)
TiffanyTuro
New Contributor III

I would like to be able to set graphics to show up only on certain pages, not on every page.  Currently when you use a graphic or text, it will show up on each page, when I really only want it on page 2, for example.

1 Comment
ChrisFox

Thank you for posting your idea. Although this is not possible through the user interface this is possible through Python. Below is a sample script that demonstrates how you can accomplish this:

import arcpy, os

#Create a reference to your map document and the Graphic Element in the map document
#"GraphicElementName" refers to the name of the element in the map document
mxd = arcpy.mapping.MapDocument(r'C:\Temp\Untitled.mxd')
graphic = arcpy.mapping.ListLayoutElements(mxd, "GRAPHIC_ELEMENT", "GraphicElementName")[0]

#Create a list of the page numbers to include the graphic on
includePicPageList = [2,4]

#Set a location for a temporary pdf used to create the mapbook
tempPDF = r'C:\Temp\Temp.pdf'

#Determine if the Final PDF exists on disk, if it does delete it and then create the PDF
finalPDFPath = r'C:\Temp\Final.pdf'
if os.path.exists(finalPDFPath):
    os.remove(finalPDFPath)
finalPDF = arcpy.mapping.PDFDocumentCreate(finalPDFPath)

for pageNum in range (1, 5):
    #Set graphic's postion off the page
    graphic.elementPositionX = -5
    graphic.elementPositionY = -5
   
    #Move to the approiate page in Data Driven Pages
    mxd.dataDrivenPages.currentPageID = pageNum

    #Determine if the current page is in the list of valid pages to include the graphic 
    for includePicPage in includePicPageList:
        if includePicPage == pageNum:
            #If the page is in the page list, set the postion of the graphic to be on the page
            graphic.elementPositionX = 1
            graphic.elementPositionY = 1

    #Export the page to the temporary PDF           
    arcpy.mapping.ExportToPDF(mxd, tempPDF)

    #Append it to the Final PDF and delete the temporary page   
    finalPDF.appendPages(tempPDF)
    os.remove(tempPDF)

#Save the pdf and delete the reference to the PDF and Map Document variables
finalPDF.saveAndClose()
del finalPDF, mxd