<?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: HELP! arcpy.mapping select records loop, export each to PDF map in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/help-arcpy-mapping-select-records-loop-export-each/m-p/90394#M7043</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You should just need to add this after your selection.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;arcpy.RefreshActiveView()&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I made a few other changes if you are interested.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;#import modules and define workspace
import arcpy
import os
import traceback

workspace = arcpy.env.workspace = r"C:/temp"
print workspace

arcpy.env.overwriteOutput = True

#Define map document
mxDoc = arcpy.mapping.MapDocument(r"C:/temp/PSL_Parcel.mxd")
print mxDoc

#List the first dataframe (named Layers) in the map document
df = arcpy.mapping.ListDataFrames(mxDoc, "Layers")[0]

#List first map layer (which is the parcels layer) in dataframe
parcelLayer = arcpy.mapping.ListLayers(mxDoc,"",df)[0]
print parcelLayer
parcelField = "APN_NU_1"

#Create a feature layer to make selections on
selectingLayer = arcpy.MakeFeatureLayer_management(parcelLayer, "parcelLayer_lyr")
row, rows = None, None
#Set up cursor:
rows = arcpy.SearchCursor(selectingLayer)

apnList = []
#Find the field, select each record and get values
for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp; apnList.append(row.getValue(parcelField))

for APN in apnList:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print(APN)
&amp;nbsp;&amp;nbsp;&amp;nbsp; whereClause = "APN_NU_1 = '{0}'".format(APN)
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.management.SelectLayerByAttribute(selectingLayer, "NEW_SELECTION", whereClause)
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.RefreshActiveView()

&amp;nbsp;&amp;nbsp;&amp;nbsp; #Export map with selected record to PDF
&amp;nbsp;&amp;nbsp;&amp;nbsp; pdfLocation = 'C:/temp'

&amp;nbsp;&amp;nbsp;&amp;nbsp; pdfName = os.path.join(pdfLocation, APN + '.pdf')

&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.ExportToPDF(mxDoc, pdfName)

print len(apnList)
del row, rows

#Clean up feature layers from memory and to debug and or rerun script
arcpy.Delete_management(selectingLayer)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 10 Dec 2021 23:27:33 GMT</pubDate>
    <dc:creator>MathewCoyle</dc:creator>
    <dc:date>2021-12-10T23:27:33Z</dc:date>
    <item>
      <title>HELP! arcpy.mapping select records loop, export each to PDF map</title>
      <link>https://community.esri.com/t5/python-questions/help-arcpy-mapping-select-records-loop-export-each/m-p/90392#M7041</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;hi ALL,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I posted my question under map automation, but it really is a python question having to do with arcpy.mapping.&amp;nbsp; I am creating a tool in python that will automate (essentially) the following process:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Find the first layer in the map document (which is the parcelLayer)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; Create a feature layer from this layer so that it can be selected&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; Get a cursor to go thru the table and find the parcel number field "APN_NU_1"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; For each parcel number, select the parcel and export the map to a pdf&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; Repeat until there are no more records to go thru.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;My script seems to be successfully iterating thru the records fine, but the pdf is not displaying the selection on the selected parcel boundary. In other words, the parcel that is selected should be highlighted on the map and then exported to pdf. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;What am I missing? I have provided the code in the text and have also attached the map document and geodatabase. My parcel feature class (for testing) only has two records, fyi.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;#import modules and define workspace
import arcpy
import os
import traceback

workspace = arcpy.env.workspace = r"C:/temp"
print workspace


arcpy.env.overwriteOutput = True

#Define map document
mxDoc = arcpy.mapping.MapDocument(r"C:/temp/PSL_Parcel.mxd")
print mxDoc

#List the first dataframe (named Layers) in the map document
df = arcpy.mapping.ListDataFrames(mxDoc, "Layers") [0]


#List first map layer (which is the parcels layer) in dataframe
parcelLayer = arcpy.mapping.ListLayers(mxDoc,"",df) [0]
print parcelLayer
parcelField = "APN_NU_1"

#Create a feature layer to make selections on
selectingLayer = arcpy.MakeFeatureLayer_management(parcelLayer, "parcelLayer_lyr")


#Set up cursor:
rows = arcpy.SearchCursor(selectingLayer)

recordsCounted = 0

#Find the field, select each record and get values 
for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp; APN = row.getValue(parcelField)
&amp;nbsp;&amp;nbsp;&amp;nbsp; whereClause = "APN_NU_1 = '%s'" % APN

&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.management.SelectLayerByAttribute(selectingLayer, "NEW_SELECTION", whereClause)
&amp;nbsp;&amp;nbsp;&amp;nbsp; print row.getValue(parcelField)



&amp;nbsp;&amp;nbsp;&amp;nbsp; recordsCounted += 1

&amp;nbsp;&amp;nbsp;&amp;nbsp; 
#Export map with selected record to PDF
&amp;nbsp;&amp;nbsp;&amp;nbsp; pdfLocation = 'C:\\temp\\'
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; pdfName = pdfLocation + APN + '.pdf'
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.ExportToPDF(mxDoc, pdfName)


&amp;nbsp;&amp;nbsp;&amp;nbsp; 
print recordsCounted&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; 
del row, rows


#Clean up feature layers from memory and to debug and or rerun script
arcpy.Delete_management(selectingLayer)
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks in advance for your help,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; Christi&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;PS. to get the attacments go to the other thread at &lt;/SPAN&gt;&lt;A href="http://forums.arcgis.com/threads/77304-HELP!python-select-records-and-export-map2PDF?p=271478#post271478" rel="nofollow noopener noreferrer" target="_blank"&gt;http://forums.arcgis.com/threads/77304-HELP!python-select-records-and-export-map2PDF?p=271478#post271478&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;PSS. I was only able to attach a .zip containing the shapefile for the parcels, rather than the geodatabase and feature class. So, the path for this would have to change in the script and you would have to add it to the map as the first layer in the TOC. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Also, save all to C:/temp!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 23:27:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/help-arcpy-mapping-select-records-loop-export-each/m-p/90392#M7041</guid>
      <dc:creator>ChristiNelson1</dc:creator>
      <dc:date>2021-12-10T23:27:30Z</dc:date>
    </item>
    <item>
      <title>Re: HELP! arcpy.mapping select records loop, export each to PDF map</title>
      <link>https://community.esri.com/t5/python-questions/help-arcpy-mapping-select-records-loop-export-each/m-p/90393#M7042</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Have you tried reading about data driven pages? it has a toolbar in Arcmap and at the same time you can use scripts to further customize it.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Cheers.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 10 Feb 2013 06:58:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/help-arcpy-mapping-select-records-loop-export-each/m-p/90393#M7042</guid>
      <dc:creator>ChrisPedrezuela</dc:creator>
      <dc:date>2013-02-10T06:58:07Z</dc:date>
    </item>
    <item>
      <title>Re: HELP! arcpy.mapping select records loop, export each to PDF map</title>
      <link>https://community.esri.com/t5/python-questions/help-arcpy-mapping-select-records-loop-export-each/m-p/90394#M7043</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You should just need to add this after your selection.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;arcpy.RefreshActiveView()&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I made a few other changes if you are interested.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;#import modules and define workspace
import arcpy
import os
import traceback

workspace = arcpy.env.workspace = r"C:/temp"
print workspace

arcpy.env.overwriteOutput = True

#Define map document
mxDoc = arcpy.mapping.MapDocument(r"C:/temp/PSL_Parcel.mxd")
print mxDoc

#List the first dataframe (named Layers) in the map document
df = arcpy.mapping.ListDataFrames(mxDoc, "Layers")[0]

#List first map layer (which is the parcels layer) in dataframe
parcelLayer = arcpy.mapping.ListLayers(mxDoc,"",df)[0]
print parcelLayer
parcelField = "APN_NU_1"

#Create a feature layer to make selections on
selectingLayer = arcpy.MakeFeatureLayer_management(parcelLayer, "parcelLayer_lyr")
row, rows = None, None
#Set up cursor:
rows = arcpy.SearchCursor(selectingLayer)

apnList = []
#Find the field, select each record and get values
for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp; apnList.append(row.getValue(parcelField))

for APN in apnList:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print(APN)
&amp;nbsp;&amp;nbsp;&amp;nbsp; whereClause = "APN_NU_1 = '{0}'".format(APN)
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.management.SelectLayerByAttribute(selectingLayer, "NEW_SELECTION", whereClause)
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.RefreshActiveView()

&amp;nbsp;&amp;nbsp;&amp;nbsp; #Export map with selected record to PDF
&amp;nbsp;&amp;nbsp;&amp;nbsp; pdfLocation = 'C:/temp'

&amp;nbsp;&amp;nbsp;&amp;nbsp; pdfName = os.path.join(pdfLocation, APN + '.pdf')

&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.ExportToPDF(mxDoc, pdfName)

print len(apnList)
del row, rows

#Clean up feature layers from memory and to debug and or rerun script
arcpy.Delete_management(selectingLayer)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 23:27:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/help-arcpy-mapping-select-records-loop-export-each/m-p/90394#M7043</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2021-12-10T23:27:33Z</dc:date>
    </item>
  </channel>
</rss>

