I have 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.
How do I 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