<?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: how to export page range in arcpy Data driven pages script in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-to-export-page-range-in-arcpy-data-driven/m-p/318127#M24699</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Alright, well you could just make a manual list in your python script, then have only loop through those numbers.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;pageNumbers = [Your page numbers here]&lt;/P&gt;&lt;P&gt;for page in pageNumbers:&lt;/P&gt;&lt;P&gt;&amp;nbsp; ...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regardless of how you do this, it is going to take some user input, so depending on how you are picking the pages, there are different ways to do this most efficiently.&amp;nbsp; The first post I had is probably the simplest way for odd pages, but if you need 1,4-9, 18-29, 33-57, then it gets a bit more complicated. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 22 Jul 2014 15:02:06 GMT</pubDate>
    <dc:creator>IanMurray</dc:creator>
    <dc:date>2014-07-22T15:02:06Z</dc:date>
    <item>
      <title>how to export page range in arcpy Data driven pages script</title>
      <link>https://community.esri.com/t5/python-questions/how-to-export-page-range-in-arcpy-data-driven/m-p/318124#M24696</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I have my script for exporting multiple DDP exports to JPEG format:&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code jive_text_macro _jivemacro_uid_14060399947017557" jivemacro_uid="_14060399947017557" modifiedtitle="true"&gt;
&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; import arcpy&lt;/P&gt;
&lt;P&gt;... mxd = arcpy.mapping.MapDocument("CURRENT")&lt;/P&gt;
&lt;P&gt;... for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1):&lt;/P&gt;
&lt;P&gt;...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd.dataDrivenPages.currentPageID = pageNum&lt;/P&gt;
&lt;P&gt;...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Exporting page {0} of {1}".format(str(mxd.dataDrivenPages.currentPageID), str(mxd.dataDrivenPages.pageCount))&lt;/P&gt;
&lt;P&gt;...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.ExportToJPEG(mxd, r"X:\DVDs to burn\South Atlantic Margins\Arcview projects\A3 &amp;amp; A4 Images and Export mxd's\2014 DDP A3 Exports\Images\Free Air" + str(pageNum) + ".jpg")&lt;/P&gt;
&lt;P&gt;... del mxd&lt;/P&gt;

&lt;/PRE&gt;&lt;P&gt;But I need to only export certain pages at a time, not the whole set!&lt;/P&gt;&lt;P&gt;In this case I want pages 1,3,5,7,9 to be exported.&lt;/P&gt;&lt;P&gt;how can I modify my script for this?&lt;/P&gt;&lt;P&gt;thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 22 Jul 2014 14:42:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-export-page-range-in-arcpy-data-driven/m-p/318124#M24696</guid>
      <dc:creator>TheoFaull</dc:creator>
      <dc:date>2014-07-22T14:42:14Z</dc:date>
    </item>
    <item>
      <title>Re: how to export page range in arcpy Data driven pages script</title>
      <link>https://community.esri.com/t5/python-questions/how-to-export-page-range-in-arcpy-data-driven/m-p/318125#M24697</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you are only needing odd numbered pages, you could use an if/else statement and use a modulo to check if there is a remainder when the page number is divided by 2.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So after mxd.dataDrivenPages.currentPageID = pageNum&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;

if int(pageNum) % 2 == 1:


&amp;nbsp; &lt;SPAN class="keyword"&gt;print&lt;/SPAN&gt; &lt;SPAN class="string"&gt;"Exporting page {0} of {1}"&lt;/SPAN&gt;.format(str(mxd.dataDrivenPages.currentPageID), str(mxd.dataDrivenPages.pageCount))


&amp;nbsp; arcpy.mapping.ExportToJPEG(mxd, r&lt;SPAN class="string"&gt;"X:\DVDs to burn\South Atlantic Margins\Arcview projects\A3 &amp;amp; A4 Images and Export mxd's\2014 DDP A3 Exports\Images\Free Air"&lt;/SPAN&gt; + str(pageNum) + &lt;SPAN class="string"&gt;".jpg"&lt;/SPAN&gt;)
else:


&amp;nbsp; continue

&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if you there are more than 10 pages and you only wanted odds up to 9, you could put an and statement in that first if statement to check if they page number is less than 10 as well.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 15:07:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-export-page-range-in-arcpy-data-driven/m-p/318125#M24697</guid>
      <dc:creator>IanMurray</dc:creator>
      <dc:date>2021-12-11T15:07:21Z</dc:date>
    </item>
    <item>
      <title>Re: how to export page range in arcpy Data driven pages script</title>
      <link>https://community.esri.com/t5/python-questions/how-to-export-page-range-in-arcpy-data-driven/m-p/318126#M24698</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;the page range could be anything. I just gave 1,3,5,7,9 as an example.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 22 Jul 2014 14:56:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-export-page-range-in-arcpy-data-driven/m-p/318126#M24698</guid>
      <dc:creator>TheoFaull</dc:creator>
      <dc:date>2014-07-22T14:56:21Z</dc:date>
    </item>
    <item>
      <title>Re: how to export page range in arcpy Data driven pages script</title>
      <link>https://community.esri.com/t5/python-questions/how-to-export-page-range-in-arcpy-data-driven/m-p/318127#M24699</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Alright, well you could just make a manual list in your python script, then have only loop through those numbers.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;pageNumbers = [Your page numbers here]&lt;/P&gt;&lt;P&gt;for page in pageNumbers:&lt;/P&gt;&lt;P&gt;&amp;nbsp; ...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regardless of how you do this, it is going to take some user input, so depending on how you are picking the pages, there are different ways to do this most efficiently.&amp;nbsp; The first post I had is probably the simplest way for odd pages, but if you need 1,4-9, 18-29, 33-57, then it gets a bit more complicated. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 22 Jul 2014 15:02:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-export-page-range-in-arcpy-data-driven/m-p/318127#M24699</guid>
      <dc:creator>IanMurray</dc:creator>
      <dc:date>2014-07-22T15:02:06Z</dc:date>
    </item>
    <item>
      <title>Re: how to export page range in arcpy Data driven pages script</title>
      <link>https://community.esri.com/t5/python-questions/how-to-export-page-range-in-arcpy-data-driven/m-p/318128#M24700</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Ian,&lt;/P&gt;&lt;P&gt;choosing the page ranges should be easy, I just don't know how or where to tell python to only export the range I ask.&lt;/P&gt;&lt;P&gt;I'm a python novice 100%. I just copied the code from Arc's help page and change the path names and export format (to .jpeg)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 22 Jul 2014 15:07:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-export-page-range-in-arcpy-data-driven/m-p/318128#M24700</guid>
      <dc:creator>TheoFaull</dc:creator>
      <dc:date>2014-07-22T15:07:38Z</dc:date>
    </item>
    <item>
      <title>Re: how to export page range in arcpy Data driven pages script</title>
      <link>https://community.esri.com/t5/python-questions/how-to-export-page-range-in-arcpy-data-driven/m-p/318129#M24701</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Theo,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;try this&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code jive_text_macro _jivemacro_uid_14060485650588790" jivemacro_uid="_14060485650588790"&gt;
&lt;P&gt;import arcpy &lt;/P&gt;
&lt;P&gt;mxd = arcpy.mapping.MapDocument("CURRENT") &lt;/P&gt;
&lt;P&gt;pageNumbers = [1,2,3,4,9,10,45] #put your page numbers in brackets separated by commas&lt;/P&gt;
&lt;P&gt;for pageNum in pageNumbers:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; mxd.dataDrivenPages.currentPageID = pageNum &lt;/P&gt;
&lt;P&gt;&amp;nbsp; print "Exporting page {0} of {1}".format(str(mxd.dataDrivenPages.currentPageID), str(mxd.dataDrivenPages.pageCount)) &lt;/P&gt;
&lt;P&gt;&amp;nbsp; arcpy.mapping.ExportToJPEG(mxd, r"X:\DVDs to burn\South Atlantic Margins\Arcview projects\A3 &amp;amp; A4 Images and Export mxd's\2014 DDP A3 Exports\Images\Free Air" + str(pageNum) + ".jpg") &lt;/P&gt;
&lt;P&gt;del mxd&lt;/P&gt;

&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;All you do is put the page numbers in the brackets separated by commas, and it should export only those page numbers, feel free to delete the ones currently in there, they are for representation only.&amp;nbsp; It just takes the list of numbers and go to each of those page numbers and exports it out.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 22 Jul 2014 17:04:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-export-page-range-in-arcpy-data-driven/m-p/318129#M24701</guid>
      <dc:creator>IanMurray</dc:creator>
      <dc:date>2014-07-22T17:04:18Z</dc:date>
    </item>
    <item>
      <title>Re: how to export page range in arcpy Data driven pages script</title>
      <link>https://community.esri.com/t5/python-questions/how-to-export-page-range-in-arcpy-data-driven/m-p/318130#M24702</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ian, thanks that works great!&lt;/P&gt;&lt;P&gt;I see you also have to delete the bit: 'pageNum &lt;SPAN class="keyword"&gt;in range(&lt;SPAN class="number"&gt;1&lt;/SPAN&gt;, mxd.dataDrivenPages.pageCount + &lt;SPAN class="number"&gt;1&lt;/SPAN&gt;):'&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="keyword"&gt;and replace it with what you put.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="keyword"&gt;thanks&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="keyword"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="keyword"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="keyword"&gt;One more question, the 2nd last line has a part where you can name the output files, in this case it says 'Free Air', but the&amp;nbsp; + str(pageNum) part adds the page number to the end of it. (ie. Free Air 1.jpg, Free Air 2.jpg etc.). Is there a way of using the name attribute from a field instead of pageNum?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="keyword"&gt;thanks&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 23 Jul 2014 08:44:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-export-page-range-in-arcpy-data-driven/m-p/318130#M24702</guid>
      <dc:creator>TheoFaull</dc:creator>
      <dc:date>2014-07-23T08:44:55Z</dc:date>
    </item>
    <item>
      <title>Re: how to export page range in arcpy Data driven pages script</title>
      <link>https://community.esri.com/t5/python-questions/how-to-export-page-range-in-arcpy-data-driven/m-p/318131#M24703</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ooh nevermind I found how to name the output files using the Name rather than the page number.&lt;/P&gt;&lt;P&gt;Here is my final code, I hope it helps someone else out:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code jive_text_macro _jivemacro_uid_14061060711218446" jivemacro_uid="_14061060711218446" modifiedtitle="true"&gt;
&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; import arcpy&lt;/P&gt;
&lt;P&gt;... mxd = arcpy.mapping.MapDocument("CURRENT") #here I choose to export from the current mxd I'm running python from&lt;/P&gt;
&lt;P&gt;... pageNumbers = [2,4,6,8] #here I have selected the page range I want exported&lt;/P&gt;
&lt;P&gt;... for pageNum in pageNumbers:&lt;/P&gt;
&lt;P&gt;...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd.dataDrivenPages.currentPageID = pageNum&lt;/P&gt;
&lt;P&gt;...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pageName = mxd.dataDrivenPages.pageRow.Name #here is a line I found elsewhere telling python where it can find the page name&lt;/P&gt;
&lt;P&gt;...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Exporting page {0} of {1}".format(str(mxd.dataDrivenPages.currentPageID), str(mxd.dataDrivenPages.pageCount))&lt;/P&gt;
&lt;P&gt;...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.ExportToTIFF(mxd, r"C:\FolderForExports\FILEname" + str(pageName) + ".tif") #here I've chose TIFF as my format and told python to add the page name to the end of each exported file&lt;/P&gt;
&lt;P&gt;... del mxd&lt;/P&gt;
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 23 Jul 2014 09:07:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-export-page-range-in-arcpy-data-driven/m-p/318131#M24703</guid>
      <dc:creator>TheoFaull</dc:creator>
      <dc:date>2014-07-23T09:07:14Z</dc:date>
    </item>
  </channel>
</rss>

