import arcpy, os
arcpy.env.overwriteOutput = True
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]
layerName = arcpy.GetParameterAsText(0)
fieldName = arcpy.GetParameterAsText(1)
imgLocation = arcpy.GetParameterAsText(2)
whereList = []
layerFile = arcpy.mapping.Layer(layerName)
layerFile.definitionQuery = ""
print df.name
with arcpy.da.SearchCursor(layerName, fieldName) as cursor:
for row in cursor:
for item in row:
whereList.append(item)
for wl in whereList:
arcpy.RefreshActiveView()
mxd.save()
layerFile.definitionQuery = fieldName + "= '" + wl + "'"
new_extent = layerFile.getExtent()
df.extent = new_extent
df.scale *= 1.5
for elm in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "title"):
if elm.name == "title":
elm.text = wl
arcpy.RefreshActiveView()
outFile = os.path.join(imgLocation, wl + ".pdf")
arcpy.AddMessage(outFile)
outFile = imgLocation + "\\" + wl + ".pdf"
arcpy.mapping.ExportToPDF(mxd, outFile, "PAGE_LAYOUT")
del mxd