AnsweredAssumed Answered

Can I export a subset of data driven pages in a scheduled process using a def query?

Question asked by timdine on Jul 18, 2012
Latest reply on Mar 19, 2013 by andyaduff
I am attempting to export a set of map books using a common index layer which has an attribute telling me which map books each feature in the index belongs to.  Interactively I can open ArcMap, change the definition query on the featureclass and refresh the data driven pages before exporting each map book.  I am attempting to do this in python so I can schedule it to update the books at a regular interval.  I could do this with a search cursor to loop through checking the attributes and append each page, although it appears the code below should work conceptually at doing what I'm attempting.  It runs (with the exception of the mxd.dataDrivenPages.refresh() line), but exports all of the features in the original unmodified definition query.  Any thoughts on if this can't work, why, or is the loop with a cursor my only option?

import arcpy mxd = arcpy.mapping.MapDocument("c:/temp/MapTemplate32KOneLine.mxd")  for myLayer in arcpy.mapping.ListLayers(mxd,'OneLineBoundaryTileEdit - 32K Index'):  myLayer.definitionQuery = "SUBTYPECD = 3 AND DEPOT LIKE '%BAR%'"  mxd.dataDrivenPages.refresh() mxd.dataDrivenPages.exportToPDF("C:/temp/BAR.pdf","ALL","","PDF_SINGLE_FILE","100","FASTEST")


Note:
The error I get from the mxd.dataDrivenPages.refresh() line is below.
Traceback (most recent call last):   File "testExportDataDrivenPages.py", line 13, in <module>     mxd.dataDrivenPages.refresh()   File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\_mapping.py", line 266, in refresh     return convertArcObjectToPythonObject(self._arc_object.refresh(*gp_fixargs((args), True))) ValueError: PageLayoutObject: Error in refreshing RefreshDataDrivenPages

Outcomes