Hi Jeff,I'm currently working on a script for exporting ddp with a mask layer and I'm having trouble getting the definition query to update for each page as it exports. I'd appreciate it if you could take a look and provide suggestions. Here's the script:
import arcpy, sys, os
arcpy.env.overwriteOutput = True
mxd = arcpy.mapping.MapDocument("CURRENT")
print "Enter save as pdf location:"
pdfDir = arcpy.GetParameterAsText(0)
outputFolder = pdfDir + r"\PDFs"
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
maskLayer = arcpy.mapping.ListLayers(mxd, "state_bnd110", df)[0]
maskField = "STATE_NAME"
for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1):
mxd.dataDrivenPages.currentPageID = pageNum
pageName = mxd.dataDrivenPages.pageRow.STATE_NAME
for lyr in arcpy.mapping.ListLayers(mxd):
if lyr.name == maskLayer:
lyr.definitionQuery = '"STATE_NAME" <> %s' % pageName
arcpy.RefreshActiveView()
arcpy.mapping.ExportToPDF(mxd, os.path.dirname(outputFolder)+ os.sep + pageName + ".pdf")
del mxd
arcpy.GetMessages()
Thanks,Karla