1

I've made a script that iterates through a set of data driven pages. Right now I have it that just the ID number of the data driven page is used in the file name to distinguish between each export. What I'm looking to do is instead of using the page ID number, I want to use an attribute from a specific field in the data driven page shapefile. Anyone have an idea how to accomplish this? I've included my script below.

import arcpy

inputList = arcpy.GetParameterAsText(0)
bckGrndLyrs = arcpy.GetParameterAsText(1)
outputLocation = arcpy.GetParameterAsText(2)
exportDPI = arcpy.GetParameterAsText(3)

mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]

for lyrs in arcpy.mapping.ListLayers(mxd, "", df):
    if lyrs.name in inputList:
        lyrs.visible = False
    elif lyrs.name in bckGrndLyrs:
        lyrs.visible = True  
    else:
        lyrs.visible = False

for inFC in arcpy.mapping.ListLayers(inputList, "", df):
    if inFC.name in inputList:
        arcpy.AddMessage("Activating " + inFC.name + " Layer")
        inFC.visible = True

        for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1):
          mxd.dataDrivenPages.currentPageID = pageNum
          for titleItem in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT"):
              if titleItem.name == 'EditedTitle':
                arcpy.AddMessage("...Changing title to " + inFC.name + " " + str(pageNum))
                titleItem.text = inFC.name 
          arcpy.AddMessage("......Refreshing Dataframe")
          arcpy.RefreshTOC()
          arcpy.RefreshActiveView()
          arcpy.AddMessage(".........Exporting " + inFC.name + " Page " + str(pageNum) + " as PDF")
          arcpy.mapping.ExportToPDF(mxd, outputLocation + " " + inFC.name + " " + str(pageNum) + ".pdf", resolution=exportDPI)
        inFC.visible = False

del mxd
  • It isn't super obvious but all the fields in the layer driving the data driven project can be pulled by inserting a data driven dynamic text and substituting the field name (support.esri.com/technical-article/000011568). It wouldn't surprise me if it is that simple. – Mike Jun 16 '16 at 19:19
  • @Mike I think you should post your comment as an answer. – PolyGeo Sep 24 '16 at 22:37

Your Answer

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

Browse other questions tagged or ask your own question.