EDIT
I was able to get my code to work, so I am replacing the erroneous code with the functioning one, in case it is useful for someone else... or if someone can show me how to make it more elegant and efficient;-)
import arcpy, string, os
mxdPath = "CURRENT"
outPath = r"D:\Working\MapBook.mxd"\Geoprocessing\CDMAPS\PDFs\MapPage\\"
outPathSitesConDist = r"D:\temp\\"\Geoprocessing\CDMAPS\MXDs_and_Geodatabase\CDMaps.mdb\Sites\SitesCD"
outputMXD = "D:\Geoprocessing\CDMAPS\MXDs_and_Geodatabase\SeriesMXDs\\"
try:
mxd = arcpy.mapping.MapDocument(mxdPath)
ddp = mxd.dataDrivenPages
df = arcpy.mapping.ListDataFrames(mxd, "Cong*")[0]
for pageNum in range(1, mxd.dataDrivenPages.pageCount +1):
pagestr
mxd.dataDrivenPages.currentPageID = pageNum
distNo = str(pageNummxd.dataDrivenPages.currentPageID)
for lyr in arcpy.mapping.ListLayersMakeFeatureLayer_management(mxd"SitesConDist", """siteLyr","[congress_dist_no] df= "+ distNo,"#","")[0]:
if
lyr.name == "Group1\Corps": defCorp = "[COnly] = 'X'"
defCoop = "[COOP] = arcpy.MakeFeatureLayer_management(corps,'X' "corpsLYR",AND "[dist_num][COnly] IS NULL"
defNSIP = ""[NSIP_Full_or_Partial] += pagestr'X'"
defDisc = "[agency_use_cd] NOT IN ( 'A' , ""'L' , ""'M' )"
arcpy.SelectLayerByAttribute_management("siteLyr","NEW_SELECTION",defCorp )
corpcnt corpscount = str(arcpy.GetCount_management("corpsLYR""siteLyr"))
arcpy.AddMessage(corpscount + " corps
gages in district " + str(pageNum))
if lyr.name == "Group1\Coop":
print corpscount + " corps gages in district " + arcpy.MakeFeatureLayer_managementstr(coop,pageNum)
"coopLYR", "[dist_num] = " + pagestr, "", "")
arcpy.SelectLayerByAttribute_management("siteLyr", "NEW_SELECTION",defCoop)
coopcnt coopcount = str(arcpy.GetCount_management("coopLYR""siteLyr"))
if lyrarcpy.nameAddMessage(coopcount ==+ "Group1\Program":" coop gages in district " + str(pageNum))
print coopcount + " arcpy.MakeFeatureLayer_management(nsip,coop "nsipLYR",gages "[dist_num]in =district " + pagestr,str(pageNum)
"", "")
arcpy.SelectLayerByAttribute_management("siteLyr", "NEW_SELECTION",defNSIP)
nsipcnt nsipcount = str(arcpy.GetCount_management("nsipLYR""siteLyr"))
if lyrarcpy.nameAddMessage(nsipcount ==+ "Group1\Discontinued":" nsip gages in district " + str(pageNum))
print nsipcount + " arcpy.MakeFeatureLayer_management(disc,nsip "discLYR",gages "[dist_num]in =district " + pagestr,str(pageNum)
"", "")
arcpy.SelectLayerByAttribute_management("siteLyr", "NEW_SELECTION",defDisc)
disccnt disccount = str(arcpy.GetCount_management("discLYR""siteLyr"))
printarcpy.AddMessage(disccount "Creating+ map" {0}discontinued ofgages {1}in district ".format( + str(mxd.dataDrivenPages.currentPageIDpageNum),)
print disccount + " discontinued gages in district " + str(mxd.dataDrivenPages.pageCount)pageNum)
for elm in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT"):
if elm.textname == "CorpsCount""CorpCount":
elm.text = elm.text.replace"("CorpsCount"," corpcnt+ corpscount + ")"
print "Corp line in legend has been replaced"
if elm.textname == "CoopCount":
elm.text = elm.text.replace"("CoopCount"," coopcnt+ coopcount + ")"
print "Coop line in legend has been replaced"
if elm.textname == "NSIPCount":
elm.text = elm.text.replace"("NSIPCount"," nsipcnt+ nsipcount + ")"
print "NSIP line in legend has been replaced"
if elm.textname == "DiscCount":
elm.text = elm.text.replace"("DiscCount"," disccnt+ disccount + ")"
print "Discontinued line in legend has been replaced"
arcpy.RefreshActiveView()
Pdf = outPath + lyrName"distNo" + str(pageNum) + ".pdf"
arcpy.mapping.ExportToPDF(mxd, Pdf)
os mxd.saveACopy(outputMXD)
#os.startfile(Pdf) -> this line can be used to preview each map as it is created
arcpy.AddMessage("Created PDF {0} of {1}".format(str(mxd.dataDrivenPages.currentPageID), str(mxd.dataDrivenPages.pageCount)))
print "Created PDF {0} of {1}".format(str(mxd.dataDrivenPages.currentPageID), str(mxd.dataDrivenPages.pageCount))
del mxd, df
except Exception, e:
import traceback
map(arcpy.AddError, traceback.format_exc().split("\n"))
arcpy.AddError(str(e))