9 Replies Latest reply on Jan 7, 2012 4:44 PM by jbarrette-esristaff

    Python to select page name and export current page using data driven pages

      I am creating a thematic mapbook in Python using some arcpy.mapping functions.  One map in the mapbook is a section map which utilizes data driven pages.  I would like the user defined parameter string of the section, township, range to be used to get to the correct data driven page.  Then I want to export only the current page to PDF.  The index field in the data driven pages is called SEC_FULL.  This is also the field used to name the pages.   I am getting stuck on how to write this in Python.  Here's what I have so far which does export the map as a PDF, but it is the wrong page. It is not finding the correct page from the user defined parameter.

      #Import arcpy module
      import string
      import arcpy
      import os
      from arcpy import mapping
      from os import sep as bs

      # Script arguments
      STR = arcpy.GetParameterAsText(0)

      #Export Section Map
      mxd = arcpy.mapping.MapDocument(r"V:\gislu\Planning\DeveloperKit\SectionMap.mxd")
      df = mapping.ListDataFrames(mxd, "STR Map")[0]
      ddp = mxd.dataDrivenPages
      Layer = mapping.ListLayers(mxd, "Section Lines", df)[0]
      clause = "\"SEC_FULL\" = '" + STR + "'"
      arcpy.AddMessage("SELECTING: " + clause)
      arcpy.SelectLayerByAttribute_management(Layer, "NEW_SELECTION", clause)
      df.scale = 9300
      pageID = ddp.getPageIDFromName("SEC_FULL")
      ddp.currentPageID = pageID
      tmpPdf = r"V:\gislu\Planning\DeveloperKit\output\Section_temp.pdf"
      ddp.exportToPDF(tmpPdf, 'CURRENT', resolution = 175)
      del mxd, tmpPdf