<?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 Re: Python and Data Driven Pages in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/python-and-data-driven-pages/m-p/455834#M35826</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Update:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;After a reboot the code worked fine with a hardcoded range.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The exportToPDF() will accept a variable string or a python range()*&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt; pageCt = mxdMain.dataDrivenPages.pageCount #=80
&amp;nbsp;&amp;nbsp;&amp;nbsp; print pageCt
&amp;nbsp;&amp;nbsp;&amp;nbsp; #outputToEnd = '"' + str(pageCount-2) + '-' + str(pageCount-1) + '"' #doesn't work
&amp;nbsp;&amp;nbsp;&amp;nbsp; #outputToEnd = str(pageCount-2) + '-' + str(pageCount-1) #doesn't work
&amp;nbsp;&amp;nbsp;&amp;nbsp; outputToEnd = range(pageCt-2, pageCt+1)&amp;nbsp; #works, but won't print first in range
&amp;nbsp;&amp;nbsp;&amp;nbsp; #outputToEnd = range(0, pageCt-77)&amp;nbsp; #works
&amp;nbsp;&amp;nbsp;&amp;nbsp; #outputToEnd = "1-2" #works
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "outputToEnd = " + str(outputToEnd)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;*but if you use a Python range it won't print the first or the last in the range (ie [7,9] will only print map 8). The last is expected (python range(7,9) = [7, 8] but skipping the first one was a surprise to me.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;then this will work fine:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;mxdMain.dataDrivenPages.exportToPDF(pdfMainOutput1, page_range_type="RANGE", page_range_string=outputToEnd, multiple_files="PDF_SINGLE_FILE", resolution=200, layers_attributes="NONE", georef_info="FALSE")&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 20:19:11 GMT</pubDate>
    <dc:creator>GrantHerbert</dc:creator>
    <dc:date>2021-12-11T20:19:11Z</dc:date>
    <item>
      <title>Python and Data Driven Pages</title>
      <link>https://community.esri.com/t5/python-questions/python-and-data-driven-pages/m-p/455833#M35825</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am having real trouble exporting to PDF - dataDrivenPages.exportToPDF()&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I can export fine if I use the defaults (just passing through a reference to the out_pdf) but as soon as I start adding parameters it fails, whether I try and pass them through or type them.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
mxdMain = arcpy.mapping.MapDocument(r"C:\Main.mxd")
pdfMainOutput1 = r"C:\ResMapMain1.pdf"
pageCount = mxdMain.dataDrivenPages.pageCount
pageStart = pageCount - 1
outputToEnd = '"' + str(pageStart) + '-' + str(pageCount) + '"'

pdfMain = mxdMain.dataDrivenPages.exportToPDF(pdfMainOutput1, page_range_type="RANGE", page_range_string=outputToEnd, multiple_files="PDF_SINGLE_FILE", resolution=200, layers_attributes="NONE", georef_info="FALSE")

&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;results in:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Traceback (most recent call last):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; File "C:\Projects\TestDDP_params.py", line 36, in &amp;lt;module&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; pdfMain = mxdMain.dataDrivenPages.exportToPDF(pdfMainOutput1, page_range_type="RANGE", page_range_string=outputToEnd, multiple_files="PDF_SINGLE_FILE", resolution=200, layers_attributes="NONE", georef_info="FALSE")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\utils.py", line 181, in fn_&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; return fn(*args, **kw)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\_mapping.py", line 400, in exportToPDF&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; return convertArcObjectToPythonObject(self._arc_object.exportToPDF(*gp_fixargs((out_pdf, page_range_type, page_range_string, multiple_files, resolution, image_quality, colorspace, compress_vectors, image_compression, picture_symbol, convert_markers, embed_fonts, layers_attributes, georef_info, jpeg_compression_quality), True)))&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;AttributeError: PageLayoutObject: Error in exporting pages&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I thought it mght have been the passing of the outputToEnd reference in the page_range parameter, but it still fails with the same error when I tried the following:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
pdfMain = mxdMain.dataDrivenPages.exportToPDF(pdfMainOutput1, page_range_type="RANGE", page_range_string="79-80", multiple_files="PDF_SINGLE_FILE", resolution=200, layers_attributes="NONE", georef_info="FALSE")
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am pretty new to Python so have I made a simple error or is there something with the dataDrivenPages that doesn't like parameters like this? I don't have the same problem with the standard arcpy.mapping.exportToPDF running on a non-data driven pages mxd - &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;pdfTitle = arcpy.mapping.ExportToPDF(mxdCover, pdfTitle, resolution=200,layers_attributes="NONE", georef_info="FALSE")&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;works fine&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 16:29:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-and-data-driven-pages/m-p/455833#M35825</guid>
      <dc:creator>GrantHerbert</dc:creator>
      <dc:date>2021-12-12T16:29:59Z</dc:date>
    </item>
    <item>
      <title>Re: Python and Data Driven Pages</title>
      <link>https://community.esri.com/t5/python-questions/python-and-data-driven-pages/m-p/455834#M35826</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Update:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;After a reboot the code worked fine with a hardcoded range.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The exportToPDF() will accept a variable string or a python range()*&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt; pageCt = mxdMain.dataDrivenPages.pageCount #=80
&amp;nbsp;&amp;nbsp;&amp;nbsp; print pageCt
&amp;nbsp;&amp;nbsp;&amp;nbsp; #outputToEnd = '"' + str(pageCount-2) + '-' + str(pageCount-1) + '"' #doesn't work
&amp;nbsp;&amp;nbsp;&amp;nbsp; #outputToEnd = str(pageCount-2) + '-' + str(pageCount-1) #doesn't work
&amp;nbsp;&amp;nbsp;&amp;nbsp; outputToEnd = range(pageCt-2, pageCt+1)&amp;nbsp; #works, but won't print first in range
&amp;nbsp;&amp;nbsp;&amp;nbsp; #outputToEnd = range(0, pageCt-77)&amp;nbsp; #works
&amp;nbsp;&amp;nbsp;&amp;nbsp; #outputToEnd = "1-2" #works
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "outputToEnd = " + str(outputToEnd)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;*but if you use a Python range it won't print the first or the last in the range (ie [7,9] will only print map 8). The last is expected (python range(7,9) = [7, 8] but skipping the first one was a surprise to me.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;then this will work fine:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;mxdMain.dataDrivenPages.exportToPDF(pdfMainOutput1, page_range_type="RANGE", page_range_string=outputToEnd, multiple_files="PDF_SINGLE_FILE", resolution=200, layers_attributes="NONE", georef_info="FALSE")&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 20:19:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-and-data-driven-pages/m-p/455834#M35826</guid>
      <dc:creator>GrantHerbert</dc:creator>
      <dc:date>2021-12-11T20:19:11Z</dc:date>
    </item>
  </channel>
</rss>

