<?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 DataDrivenPages exporting a selection in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/datadrivenpages-exporting-a-selection/m-p/396166#M31271</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm working through the examples in the online help, example #3 shows how to export a selection of records rather than everything. &lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy mxd = arcpy.mapping.MapDocument(r"C:\Project\ParcelAtlas.mxd") ddp = mxd.dataDrivenPages indexLayer = ddp.indexLayer arcpy.SelectLayerByAttribute_management(indexLayer, "NEW_SELECTION",&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; '"PageNumber" &amp;gt;= 1 AND "PageNumber" &amp;lt;= 10') for indexPage in ddp.selectedPages: &amp;nbsp; ddp.currentPageID = indexPage &amp;nbsp; ddp.exportToPDF(r"C:\Project\Output\Page" + str(indexPage) + ".pdf", "CURRENT")&amp;nbsp; del mxd&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have DDP setup on a mxd and when I run the script it always exports ALL the records. The changes I made to the script only pertain to the mxd patch, destination path and field name that is the index layer. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy mxd = arcpy.mapping.MapDocument(r"C:\MapSAR\New_Incident_Z11\Map_Templates\MapSAR_ANSI_A_8x11_Letter_Landscape_DDP.mxd") ddp = mxd.dataDrivenPages indexLayer = ddp.indexLayer arcpy.SelectLayerByAttribute_management(indexLayer, "NEW_SELECTION",'"Assignment_Number" &amp;gt; 1 AND "Assignment_Number" &amp;lt; 3') for indexPage in ddp.selectedPages: &amp;nbsp; ddp.currentPageID = indexPage &amp;nbsp; ddp.exportToPDF(r"C:\MapSAR\New_Incident_Z11\Products\page" + str(indexPage) + ".pdf", "CURRENT")&amp;nbsp; del mxd&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;can anyone either point out what I'm doing incorrectly or even better if there's other code examples I might learn from. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Jon&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 13 Dec 2012 20:20:57 GMT</pubDate>
    <dc:creator>JonPedder</dc:creator>
    <dc:date>2012-12-13T20:20:57Z</dc:date>
    <item>
      <title>DataDrivenPages exporting a selection</title>
      <link>https://community.esri.com/t5/python-questions/datadrivenpages-exporting-a-selection/m-p/396166#M31271</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm working through the examples in the online help, example #3 shows how to export a selection of records rather than everything. &lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy mxd = arcpy.mapping.MapDocument(r"C:\Project\ParcelAtlas.mxd") ddp = mxd.dataDrivenPages indexLayer = ddp.indexLayer arcpy.SelectLayerByAttribute_management(indexLayer, "NEW_SELECTION",&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; '"PageNumber" &amp;gt;= 1 AND "PageNumber" &amp;lt;= 10') for indexPage in ddp.selectedPages: &amp;nbsp; ddp.currentPageID = indexPage &amp;nbsp; ddp.exportToPDF(r"C:\Project\Output\Page" + str(indexPage) + ".pdf", "CURRENT")&amp;nbsp; del mxd&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have DDP setup on a mxd and when I run the script it always exports ALL the records. The changes I made to the script only pertain to the mxd patch, destination path and field name that is the index layer. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy mxd = arcpy.mapping.MapDocument(r"C:\MapSAR\New_Incident_Z11\Map_Templates\MapSAR_ANSI_A_8x11_Letter_Landscape_DDP.mxd") ddp = mxd.dataDrivenPages indexLayer = ddp.indexLayer arcpy.SelectLayerByAttribute_management(indexLayer, "NEW_SELECTION",'"Assignment_Number" &amp;gt; 1 AND "Assignment_Number" &amp;lt; 3') for indexPage in ddp.selectedPages: &amp;nbsp; ddp.currentPageID = indexPage &amp;nbsp; ddp.exportToPDF(r"C:\MapSAR\New_Incident_Z11\Products\page" + str(indexPage) + ".pdf", "CURRENT")&amp;nbsp; del mxd&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;can anyone either point out what I'm doing incorrectly or even better if there's other code examples I might learn from. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Jon&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Dec 2012 20:20:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/datadrivenpages-exporting-a-selection/m-p/396166#M31271</guid>
      <dc:creator>JonPedder</dc:creator>
      <dc:date>2012-12-13T20:20:57Z</dc:date>
    </item>
    <item>
      <title>Re: DataDrivenPages exporting a selection</title>
      <link>https://community.esri.com/t5/python-questions/datadrivenpages-exporting-a-selection/m-p/396167#M31272</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I just copy/pasted your second code snippet, made minor path and query changes, and ran it just fine in 10.1 sp1.&amp;nbsp; Here is the code I used.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import arcpy
mxd = arcpy.mapping.MapDocument(r"C:\Temp\Untitled.mxd")
ddp = mxd.dataDrivenPages
indexLayer = ddp.indexLayer
arcpy.SelectLayerByAttribute_management(indexLayer, "NEW_SELECTION", "\"State_Name\" = 'Rhode Island'")
#arcpy.SelectLayerByAttribute_management(indexLayer, "NEW_SELECTION", '"SHAPE_AREA" &amp;gt; 0')
for indexPage in ddp.selectedPages:
&amp;nbsp; ddp.currentPageID = indexPage
&amp;nbsp; ddp.exportToPDF(r"C:\Temp\\" + str(indexPage) + ".pdf", "CURRENT")
del mxd
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Comment out your SelectLayerByAttribute line and run the code.&amp;nbsp; Nothing should get exported unless you have saved features in your MXD.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Jeff&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 18:07:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/datadrivenpages-exporting-a-selection/m-p/396167#M31272</guid>
      <dc:creator>JeffBarrette</dc:creator>
      <dc:date>2021-12-11T18:07:32Z</dc:date>
    </item>
    <item>
      <title>Re: DataDrivenPages exporting a selection</title>
      <link>https://community.esri.com/t5/python-questions/datadrivenpages-exporting-a-selection/m-p/396168#M31273</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks Jeff. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I found the issue. The FC are Joined so I need complete joined field name assignments.assignment_number &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Jon&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Dec 2012 15:43:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/datadrivenpages-exporting-a-selection/m-p/396168#M31273</guid>
      <dc:creator>JonPedder</dc:creator>
      <dc:date>2012-12-14T15:43:42Z</dc:date>
    </item>
  </channel>
</rss>

