<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Python to select page name and export current page using data driven pages in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/python-to-select-page-name-and-export-current-page/m-p/504086#M39573</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am creating a thematic mapbook in Python using some arcpy.mapping functions.&amp;nbsp; One map in the mapbook is a section map which utilizes data driven pages.&amp;nbsp; I would like the user defined parameter string of the section, township, range to be used to get to the correct data driven page.&amp;nbsp; Then I want to export only the current page to PDF.&amp;nbsp; The index field in the data driven pages is called SEC_FULL.&amp;nbsp; This is also the field used to name the pages.&amp;nbsp;&amp;nbsp; I am getting stuck on how to write this in Python.&amp;nbsp; 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.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#Import arcpy module&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import string&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import arcpy&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import os&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;from arcpy import mapping&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;from os import sep as bs&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Script arguments&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;STR = arcpy.GetParameterAsText(0)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#Export Section Map&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;mxd = arcpy.mapping.MapDocument(r"V:\gislu\Planning\DeveloperKit\SectionMap.mxd")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;df = mapping.ListDataFrames(mxd, "STR Map")[0]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ddp = mxd.dataDrivenPages&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Layer = mapping.ListLayers(mxd, "Section Lines", df)[0]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;clause = "\"SEC_FULL\" = '" + STR + "'"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.AddMessage("SELECTING: " + clause)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.SelectLayerByAttribute_management(Layer, "NEW_SELECTION", clause)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.AddMessage(arcpy.GetCount_management(Layer).getOutput(0))&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;df.zoomToSelectedFeatures()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;df.scale = 9300&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.RefreshActiveView() &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;pageID = ddp.getPageIDFromName("SEC_FULL")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ddp.currentPageID = pageID&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;tmpPdf = r"V:\gislu\Planning\DeveloperKit\output\Section_temp.pdf"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ddp.exportToPDF(tmpPdf, 'CURRENT', resolution = 175)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;finalPdf.appendPages(tmpPdf)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;del mxd, tmpPdf&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 06 Jan 2012 13:35:37 GMT</pubDate>
    <dc:creator>MollyWatson</dc:creator>
    <dc:date>2012-01-06T13:35:37Z</dc:date>
    <item>
      <title>Python to select page name and export current page using data driven pages</title>
      <link>https://community.esri.com/t5/python-questions/python-to-select-page-name-and-export-current-page/m-p/504086#M39573</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am creating a thematic mapbook in Python using some arcpy.mapping functions.&amp;nbsp; One map in the mapbook is a section map which utilizes data driven pages.&amp;nbsp; I would like the user defined parameter string of the section, township, range to be used to get to the correct data driven page.&amp;nbsp; Then I want to export only the current page to PDF.&amp;nbsp; The index field in the data driven pages is called SEC_FULL.&amp;nbsp; This is also the field used to name the pages.&amp;nbsp;&amp;nbsp; I am getting stuck on how to write this in Python.&amp;nbsp; 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.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#Import arcpy module&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import string&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import arcpy&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import os&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;from arcpy import mapping&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;from os import sep as bs&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Script arguments&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;STR = arcpy.GetParameterAsText(0)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#Export Section Map&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;mxd = arcpy.mapping.MapDocument(r"V:\gislu\Planning\DeveloperKit\SectionMap.mxd")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;df = mapping.ListDataFrames(mxd, "STR Map")[0]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ddp = mxd.dataDrivenPages&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Layer = mapping.ListLayers(mxd, "Section Lines", df)[0]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;clause = "\"SEC_FULL\" = '" + STR + "'"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.AddMessage("SELECTING: " + clause)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.SelectLayerByAttribute_management(Layer, "NEW_SELECTION", clause)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.AddMessage(arcpy.GetCount_management(Layer).getOutput(0))&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;df.zoomToSelectedFeatures()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;df.scale = 9300&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.RefreshActiveView() &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;pageID = ddp.getPageIDFromName("SEC_FULL")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ddp.currentPageID = pageID&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;tmpPdf = r"V:\gislu\Planning\DeveloperKit\output\Section_temp.pdf"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ddp.exportToPDF(tmpPdf, 'CURRENT', resolution = 175)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;finalPdf.appendPages(tmpPdf)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;del mxd, tmpPdf&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Jan 2012 13:35:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-to-select-page-name-and-export-current-page/m-p/504086#M39573</guid>
      <dc:creator>MollyWatson</dc:creator>
      <dc:date>2012-01-06T13:35:37Z</dc:date>
    </item>
    <item>
      <title>Re: Python to select page name and export current page using data driven pages</title>
      <link>https://community.esri.com/t5/python-questions/python-to-select-page-name-and-export-current-page/m-p/504087#M39574</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I think your problem might be your clause string.&amp;nbsp; I tried typing the same text in the Python window and got a runtime error.&amp;nbsp; What do you want the clause value to be?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Jan 2012 15:11:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-to-select-page-name-and-export-current-page/m-p/504087#M39574</guid>
      <dc:creator>JeffWard</dc:creator>
      <dc:date>2012-01-06T15:11:44Z</dc:date>
    </item>
    <item>
      <title>Re: Python to select page name and export current page using data driven pages</title>
      <link>https://community.esri.com/t5/python-questions/python-to-select-page-name-and-export-current-page/m-p/504088#M39575</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Scratch that, I needed to create the STR variable.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Jan 2012 15:18:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-to-select-page-name-and-export-current-page/m-p/504088#M39575</guid>
      <dc:creator>JeffWard</dc:creator>
      <dc:date>2012-01-06T15:18:25Z</dc:date>
    </item>
    <item>
      <title>Re: Python to select page name and export current page using data driven pages</title>
      <link>https://community.esri.com/t5/python-questions/python-to-select-page-name-and-export-current-page/m-p/504089#M39576</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I don't think you need to go through all of the selection code.&amp;nbsp; If you replace "SEC_FULL" with the STR variable, it should change to the section entered by the user.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;pageID = ddp.getPageIDFromName(STR)
ddp.currentPageID = pageID&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Then you can get rid of all of the selectLayerByAttribute_management code.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;As long as the user enters the section correctly it should work.&amp;nbsp; You might want to put some error handling code in to make sure they type the section correctly.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 22:07:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-to-select-page-name-and-export-current-page/m-p/504089#M39576</guid>
      <dc:creator>JeffWard</dc:creator>
      <dc:date>2021-12-11T22:07:08Z</dc:date>
    </item>
    <item>
      <title>Re: Python to select page name and export current page using data driven pages</title>
      <link>https://community.esri.com/t5/python-questions/python-to-select-page-name-and-export-current-page/m-p/504090#M39577</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You will also want to use os.remove(tmpPdf) to delete the temporary pdf file.&amp;nbsp; The del command is for object cleanup which you have a bunch of - ddp, df, Layer, and mxd.&amp;nbsp; Where you don't need to do the layer selection, I think the only objects you need are the mxd and ddp objects.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Jan 2012 16:23:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-to-select-page-name-and-export-current-page/m-p/504090#M39577</guid>
      <dc:creator>JeffWard</dc:creator>
      <dc:date>2012-01-06T16:23:48Z</dc:date>
    </item>
    <item>
      <title>Re: Python to select page name and export current page using data driven pages</title>
      <link>https://community.esri.com/t5/python-questions/python-to-select-page-name-and-export-current-page/m-p/504091#M39578</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;#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")
ddp = mxd.dataDrivenPages
pageID = ddp.getPageIDFromName(STR)
ddp.currentPageID = pageID
tmpPdf = r"V:\gislu\Planning\DeveloperKit\output\Section_temp.pdf"
ddp.exportToPDF(tmpPdf, 'CURRENT', resolution = 175)
finalPdf.appendPages(tmpPdf)
os.remove(tmpPdf)
del mxd, ddp&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;the line: &lt;/SPAN&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;finalPdf.appendPages(tmpPdf)
&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;probably won't work because finalPdf isn't defined.&amp;nbsp; I am assuming you have it defined in code that you didn't include in your post.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 22:07:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-to-select-page-name-and-export-current-page/m-p/504091#M39578</guid>
      <dc:creator>JeffWard</dc:creator>
      <dc:date>2021-12-11T22:07:11Z</dc:date>
    </item>
    <item>
      <title>Re: Python to select page name and export current page using data driven pages</title>
      <link>https://community.esri.com/t5/python-questions/python-to-select-page-name-and-export-current-page/m-p/504092#M39579</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks Jeff. I do have the os.remove(tmpPDF) command at the end of the script to remove all of the temporary pdfs.&amp;nbsp; I also have defined the finalPDF at the beginning of the script which I did not include.&amp;nbsp; I tried your suggestion of removing the selection piece and replacing the SEC_FULL with the STR parameter. This is what the new code section looks like:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#Select and Zoom To Section Map, Export, and Append&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;mxd = arcpy.mapping.MapDocument(r"V:\gislu\Planning\DeveloperKit\SectionMap.mxd")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;df = mapping.ListDataFrames(mxd, "STR Map")[0]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ddp = mxd.dataDrivenPages&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;pageID = ddp.getPageIDFromName(STR)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ddp.currentPageID = pageID&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;tmpPdf = r"V:\gislu\Planning\DeveloperKit\output\Section_temp.pdf"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ddp.exportToPDF(tmpPdf, 'CURRENT', resolution = 175)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;finalPdf.appendPages(tmpPdf)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;del mxd, tmpPdf, ddp&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I typed the user defined parameter exactly the same way it is shown in the SEC_FULL field in the attribute table.&amp;nbsp; I got the following error:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;lt;type 'exceptions.ValueError'&amp;gt;: u'T1S R70W S30'&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Failed to execute (MapbookSection).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any other suggestions?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Jan 2012 18:50:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-to-select-page-name-and-export-current-page/m-p/504092#M39579</guid>
      <dc:creator>MollyWatson</dc:creator>
      <dc:date>2012-01-06T18:50:08Z</dc:date>
    </item>
    <item>
      <title>Re: Python to select page name and export current page using data driven pages</title>
      <link>https://community.esri.com/t5/python-questions/python-to-select-page-name-and-export-current-page/m-p/504093#M39580</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Have you tried hard coding the text into the program?&amp;nbsp; It may be a problem with getting the STR variable from the GetParameterAsText function.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;pageID = ddp.getPageIDFromName('T1S R70W S30')&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If that works maybe try placing your GetParameterAsText function in the str() function.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;STR = str(arcpy.GetParameterAsText(0))&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Jan 2012 19:18:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-to-select-page-name-and-export-current-page/m-p/504093#M39580</guid>
      <dc:creator>JeffWard</dc:creator>
      <dc:date>2012-01-06T19:18:14Z</dc:date>
    </item>
    <item>
      <title>Re: Python to select page name and export current page using data driven pages</title>
      <link>https://community.esri.com/t5/python-questions/python-to-select-page-name-and-export-current-page/m-p/504094#M39581</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;That worked! Thank you so much! The file size of the final mapbook is too large to attach. If you would like a copy of the entire script let me know.&amp;nbsp; It writes a title page, TOC, vicinity map, section map, and several thematic maps zoomed in on a particular property and appends it into 1 PDF. We got the idea from Clark County, WA here: &lt;/SPAN&gt;&lt;A href="http://gis.clark.wa.gov/gishome/WebOrders/?pid=goDevPacket"&gt;http://gis.clark.wa.gov/gishome/WebOrders/?pid=goDevPacket&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Jan 2012 19:49:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-to-select-page-name-and-export-current-page/m-p/504094#M39581</guid>
      <dc:creator>MollyWatson</dc:creator>
      <dc:date>2012-01-06T19:49:18Z</dc:date>
    </item>
    <item>
      <title>Re: Python to select page name and export current page using data driven pages</title>
      <link>https://community.esri.com/t5/python-questions/python-to-select-page-name-and-export-current-page/m-p/504095#M39582</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;There are a couple of already existing samples on the resource center:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://resources.arcgis.com/gallery/file/geoprocessing/details?entryID=A910AB18-1422-2418-3418-3885D388EF60"&gt;http://resources.arcgis.com/gallery/file/geoprocessing/details?entryID=A910AB18-1422-2418-3418-3885D388EF60&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;There is one called Print Data Driven Page(s).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Jeff&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 08 Jan 2012 00:44:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-to-select-page-name-and-export-current-page/m-p/504095#M39582</guid>
      <dc:creator>JeffBarrette</dc:creator>
      <dc:date>2012-01-08T00:44:14Z</dc:date>
    </item>
  </channel>
</rss>

