I am trying to loop through exporting data drive pages, select data from another layer based on the page getting exported, and write a row of the results of the selection to a text element. Each page should have different results in text element. For each page getting exported I I want to select all the parcels within the current page/feature getting exported and write the results to the text element. What I have so far only writes the results for the first page on every page. When it runs it does seem to select the parcels per page while exporting, but it does not re-write the results to the text element. Not sure what I am missing?
# Always run script in the mxd you are working on. mxd = arcpy.mapping.MapDocument("CURRENT") # Overwrites any existing features. arcpy.env.overwriteOutput = True # Uses the Dataframe called "Layers". df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0] # Parcel Text Element ParcelText2 = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "ParcelsText2")[0] # Data Driven Pages Export Sheets ExportSheets = arcpy.mapping.Layer("Sheets_11x17") # Parcels Parcels = arcpy.mapping.Layer("Parcels") # Data Driven Pages mxd abbreviation ddp = mxd.dataDrivenPages # Loop through DDP's for pageNumb in range(1, mxd.dataDrivenPages.pageCount + 1): ddp.currentPageID = pageNumb # DDP Export Sheet duplicate which has the page definition Query SelectedSheet = arcpy.mapping.Layer("Sheets_11x172") # Exports Row page ExportSheetsPage = ddp.pageRow.PLAN_NUMBER # Select Parcels withing my SelectedSheet arcpy.SelectLayerByLocation_management(Parcels, "WITHIN", SelectedSheet) # Use SearchCursor to get Parcels value and write to Parcel Text Element rows = arcpy.SearchCursor(Parcels) textValue = "" for row in rows: textValue += row.getValue("MAP_PARCEL") ParcelText2.text = textValue # Export Sheets ddp.exportToPDF(r"Y:\GIS\GIS_Work\Working\parcel_test\maps\test.mxd")
Solved! Go to Solution.
Try putting the ALL keyword in your export statement ArcGIS Help 10.1
ddp.exportToPDF(r"Y:\GIS\GIS_Work\Working\parcel_test\maps\test.pdf","ALL")
Try refreshing the active view right before you export the PDF.
arcpy.RefreshActiveView()
Try putting the ALL keyword in your export statement ArcGIS Help 10.1
ddp.exportToPDF(r"Y:\GIS\GIS_Work\Working\parcel_test\maps\test.pdf","ALL")
I got it figured out. I think "ALL" might work, but yes the keyword was the issue. I ended up doing sort of a similar thing, I created a new pdf document before the loop, exported each sheet as "CURRENT" then appended the pages to the new pdf. Thanks for the help.