AnsweredAssumed Answered

Python Data Driven Pages does not loop through list

Question asked by dswhitney77 on Jan 16, 2013
Latest reply on Feb 8, 2013 by BenHolmes
I am new to python (and the forum) and am trying to export data driven pages with a definition query. I have a list (right now only two items) for the ddp to loop through. The final pdf files have the correct name and cover sheet, but the map data is the same in both files and is not one of the items in the list. It looks like I have a problem with my definition query, but have hit a wall on what could be the problem.

# Import ArcPy import arcpy  # Set up variables # Location of pole map .mxd document mxdDoc = r"G:\GEOSPATIAL\Publishing\Pole\Pole_QtrSec.mxd"  # Create the MapDocument object mxd = arcpy.mapping.MapDocument(mxdDoc) layers = arcpy.mapping.ListLayers (mxd, "SURVEY_GRID_BNDRY")  # Overwrite an existing file arcpy.env.overwriteOutput = True  # Output directory for the pole maps outDir = r"G:\GEOSPATIAL\Publishing\Pole"  # Set the workspace arcpy.env.workspace = outDir  twpList = ['\"TOWNSHIP_C\" = \'D5\' AND \"RANGE_CD\" = \'7\'',\            '\"TOWNSHIP_C\" = \'D6\' AND \"RANGE_CD\" = \'7\'']  for twpName in twpList:     layers[0].definitionQuery = twpName     print layers[0].definitionQuery          # The final mapbook name taken from the list     finalPDFfn = outDir + "\\" + twpName [16:18] + twpName [38:39] + "Pole.pdf"          # Create the final PDF -- which is just an empty shell right now     finalPDF = arcpy.mapping.PDFDocumentCreate(finalPDFfn)      # A temporary pdf file for processing     tmpPDF = outDir + "\\PoleMapPages.pdf"      # Let the user know what is happening!     print "Exporting " + twpName [16:18] + twpName [38:39]          # Export the data driven pages in the mxd to a temporary PDF     print "Exporting map pages to the temporary PDF"     ddp = mxd.dataDrivenPages.exportToPDF(tmpPDF)      # Append the temporary pdf to the final pdf     # Cover, map pages, back cover     print "Appending Map Pages"     finalPDF.appendPages (r"G:\GEOSPATIAL\Publishing\Pole\PoleCovers\Covers_" + twpName [16:18] + twpName [38:39] + ".pdf")     finalPDF.appendPages(tmpPDF)     finalPDF.appendPages(r"G:\GEOSPATIAL\Publishing\TwpGrid_Color8x11.pdf")      # Set properties for Adobe Reader and save PDF.     finalPDF.updateDocProperties(pdf_open_view = "USE_THUMBS", pdf_layout = "SINGLE_PAGE")     finalPDF.saveAndClose()  # Clean up print "Cleaning up" # Delete the temporary PDF using the ArcPy function if arcpy.Exists(tmpPDF):                  arcpy.Delete_management(tmpPDF)   # Delete objects del mxd, tmpPDF, ddp