OK!!This code works pretty darn well.. Only problem Each export is being given the dataframe of the Previous layer. what happens is this the first export gets the correct data frame, the second gets the first, the third gets the second, the fourth gets the third etc. What could be causing that?
import arcpy
import time
arcpy.env.overwriteOutput = True
mxd = arcpy.mapping.MapDocument("CURRENT")
textlist = arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT")
for txt in textlist:
if txt.text == r"MAP SUBTITLE":
subtitle = txt
layerlist = arcpy.mapping.ListLayers(mxd)
df = arcpy.mapping.ListDataFrames(mxd)[0]
for lyr in layerlist:
if lyr.longName != lyr.name:
if "flow" in lyr.name.lower():
arcpy.SelectLayerByAttribute_management(lyr, "NEW_SELECTION")
df.zoomToSelectedFeatures()
arcpy.SelectLayerByAttribute_management(lyr, "CLEAR_SELECTION")
df.scale = df.scale * 1.15
arcpy.RefreshActiveView()
if lyr.visible == False:
lyr.visible = True
subtitle.text = lyr.name
time.sleep(3)
pdfpath = "C://Users//user//Desktop//DDP_TEMP//" + lyr.name + r" mapbook.pdf"
print "Exporting " + pdfpath + "....."
arcpy.mapping.ExportToPDF(mxd, pdfpath)
lyr.visible = False
del mxd, df
print "Done!"