<?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!python select records and export map2PDF in Mapping Questions</title>
    <link>https://community.esri.com/t5/mapping-questions/help-python-select-records-and-export-map2pdf/m-p/269227#M2836</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Original User: christi_nelson&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;pdf is attached&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;PS - I am running ArcGIS 10.0&amp;nbsp; (ArcInfo level)&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 11 Feb 2013 13:39:39 GMT</pubDate>
    <dc:creator>Anonymous User</dc:creator>
    <dc:date>2013-02-11T13:39:39Z</dc:date>
    <item>
      <title>HELP!python select records and export map2PDF</title>
      <link>https://community.esri.com/t5/mapping-questions/help-python-select-records-and-export-map2pdf/m-p/269223#M2832</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Original User: christi_nelson&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am creating a tool in python that will automate (essentially) the following process:&lt;/SPAN&gt;&lt;BR /&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;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.&amp;nbsp; 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?&amp;nbsp; I have provided the code in the text and have also attached the map document and geodatabase.&amp;nbsp; My parcel feature class (for testing) only has two records, fyi.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;#import modules and define workspace import arcpy import os import traceback&amp;nbsp; workspace = arcpy.env.workspace = r"C:/temp" print workspace&amp;nbsp;&amp;nbsp; arcpy.env.overwriteOutput = True&amp;nbsp; #Define map document mxDoc = arcpy.mapping.MapDocument(r"C:/temp/PSL_Parcel.mxd") print mxDoc&amp;nbsp; #List the first dataframe (named Layers) in the map document df = arcpy.mapping.ListDataFrames(mxDoc, "Layers") [0]&amp;nbsp;&amp;nbsp; #List first map layer (which is the parcels layer) in dataframe parcelLayer = arcpy.mapping.ListLayers(mxDoc,"",df) [0] print parcelLayer parcelField = "APN_NU_1"&amp;nbsp; #Create a feature layer to make selections on selectingLayer = arcpy.MakeFeatureLayer_management(parcelLayer, "parcelLayer_lyr")&amp;nbsp;&amp;nbsp; #Set up cursor: rows = arcpy.SearchCursor(selectingLayer)&amp;nbsp; recordsCounted = 0&amp;nbsp; #Find the field, select each record and get values&amp;nbsp; 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;&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; &amp;nbsp;&amp;nbsp;&amp;nbsp; recordsCounted += 1&amp;nbsp; &amp;nbsp;&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;&amp;nbsp; pdfName = pdfLocation + APN + '.pdf' &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.ExportToPDF(mxDoc, pdfName)&amp;nbsp;&amp;nbsp; &amp;nbsp;&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;&amp;nbsp; del row, rows&amp;nbsp;&amp;nbsp; #Clean up feature layers from memory and to debug and or rerun script arcpy.Delete_management(selectingLayer)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&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;BR /&gt;&lt;SPAN&gt;PS.&amp;nbsp; I was only able to attach a .zip containing the shapefile for the parcels, rather than the geodatabase and feature class.&amp;nbsp; 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.&amp;nbsp; Also, save all to C:/temp!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Feb 2013 19:13:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/help-python-select-records-and-export-map2pdf/m-p/269223#M2832</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2013-02-08T19:13:06Z</dc:date>
    </item>
    <item>
      <title>Re: HELP!python select records and export map2PDF</title>
      <link>https://community.esri.com/t5/mapping-questions/help-python-select-records-and-export-map2pdf/m-p/269224#M2833</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Original User: JeffMoulds&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Try this...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For each county (in your case, parcel) that matches the where clause in the Search Cursor, I select it, then set the extent of the data frame to be that of the selected feature (plus 10%), then I export it it to pdf.&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\temp.mxd")
df = arcpy.mapping.ListDataFrames(mxd, 'Layers')[0]
Layer = arcpy.mapping.ListLayers(mxd, "*Counties*")[0]
county = 'Red River'
sql1 = "\"NAME\" = " + "\'" + county + "\'"
rows = arcpy.SearchCursor(Layer, sql1)
for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print row.getValue('OBJECTID')
&amp;nbsp;&amp;nbsp;&amp;nbsp; oid = str(row.getValue('OBJECTID'))
&amp;nbsp;&amp;nbsp;&amp;nbsp; sql2 = "\"OBJECTID\" = " + oid
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management(Layer, "NEW_SELECTION", sql2)
&amp;nbsp;&amp;nbsp;&amp;nbsp; df.extent = Layer.getSelectedExtent(False)
&amp;nbsp;&amp;nbsp;&amp;nbsp; df.scale = df.scale * 1.1
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.ExportToPDF(mxd, r"C:\Temp\RedRiver" + oid + ".pdf")&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 13:10:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/help-python-select-records-and-export-map2pdf/m-p/269224#M2833</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-12-11T13:10:46Z</dc:date>
    </item>
    <item>
      <title>Re: HELP!python select records and export map2PDF</title>
      <link>https://community.esri.com/t5/mapping-questions/help-python-select-records-and-export-map2pdf/m-p/269225#M2834</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Try this...&lt;BR /&gt;&lt;BR /&gt;For each county (in your case, parcel) that matches the where clause in the Search Cursor, I select it, then set the extent of the data frame to be that of the selected feature (plus 10%), then I export it it to pdf.&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\temp.mxd")
df = arcpy.mapping.ListDataFrames(mxd, 'Layers')[0]
Layer = arcpy.mapping.ListLayers(mxd, "*Counties*")[0]
county = 'Red River'
sql1 = "\"NAME\" = " + "\'" + county + "\'"
rows = arcpy.SearchCursor(Layer, sql1)
for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print row.getValue('OBJECTID')
&amp;nbsp;&amp;nbsp;&amp;nbsp; oid = str(row.getValue('OBJECTID'))
&amp;nbsp;&amp;nbsp;&amp;nbsp; sql2 = "\"OBJECTID\" = " + oid
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management(Layer, "NEW_SELECTION", sql2)
&amp;nbsp;&amp;nbsp;&amp;nbsp; df.extent = Layer.getSelectedExtent(False)
&amp;nbsp;&amp;nbsp;&amp;nbsp; df.scale = df.scale * 1.1
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.ExportToPDF(mxd, r"C:\Temp\RedRiver" + oid + ".pdf")&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks, Jeff I will try this and let you know.&amp;nbsp; In the mean time, can you please tell me why you would set the Layer.getSelectedExtent to False?&amp;nbsp; What does this do and what would happen if you set it to True?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 13:10:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/help-python-select-records-and-export-map2pdf/m-p/269225#M2834</guid>
      <dc:creator>ChristiNelson1</dc:creator>
      <dc:date>2021-12-11T13:10:49Z</dc:date>
    </item>
    <item>
      <title>Re: HELP!python select records and export map2PDF</title>
      <link>https://community.esri.com/t5/mapping-questions/help-python-select-records-and-export-map2pdf/m-p/269226#M2835</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Jeff,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I tried your method and it definitely runs and creates the pdfs.&amp;nbsp; But it doesn't zoom into the parcel and the pdf doesnt show the highlighted (selected) parcel.&amp;nbsp; See attached .pdf.&amp;nbsp; Ideas?&amp;nbsp; I used the script below.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Additional questions regarding your script:&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1.&amp;nbsp; Why did you not have to create a feature layer (MakeFeatureLayerManagement) before performing a selectbyattribute?&amp;nbsp; All the documentation I've read says you must make a feature layer first.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2. What do the *asterisks* do in your arpy.ListLayers (mxd, "*Counties*") script?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;3. I also ran the script below with&amp;nbsp; df.extent = parcelLayer.getSelectedExtent (&lt;/SPAN&gt;&lt;STRONG&gt;True&lt;/STRONG&gt;&lt;SPAN&gt;) but it didn't make a difference. What does the True/False do?&lt;/SPAN&gt;&lt;BR /&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"E:/Projects/PSL"
print workspace


arcpy.env.overwriteOutput = True

#Define map document
mxDoc = arcpy.mapping.MapDocument(r"E:/Projects/PSL/PSL_Parcel.mxd")
print mxDoc

#List the first dataframe (named Layers) in the map document
df = arcpy.mapping.ListDataFrames(mxDoc, "Layers") [0]
print df

#List first map layer (which is the parcels layer) in dataframe
parcelLayer = arcpy.mapping.ListLayers(mxDoc,"",df) [0]



#Set up a Search Cursor to go thru the attribute table and get row values to update the layout text 
#First set up variable, then read the row values and verify
recordsCounted = 0
rows = arcpy.SearchCursor(parcelLayer)
for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print row.getValue('APN_NU_1')
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; APN = row.getValue('APN_NU_1')

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; whereClause = """ 'APN_NU_1' = APN """
&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; arcpy.SelectLayerByAttribute_management(parcelLayer, "NEW_SELECTION", whereClause)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; df.extent = parcelLayer.getSelectedExtent (False)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; df.scale = df.scale * 1.1
&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; recordsCounted += 1

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pdfLocation = 'E:\\Projects\\PSL\\temp\\' 
&amp;nbsp;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.ExportToPDF(mxDoc, pdfName)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 13:10:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/help-python-select-records-and-export-map2pdf/m-p/269226#M2835</guid>
      <dc:creator>ChristiNelson1</dc:creator>
      <dc:date>2021-12-11T13:10:51Z</dc:date>
    </item>
    <item>
      <title>Re: HELP!python select records and export map2PDF</title>
      <link>https://community.esri.com/t5/mapping-questions/help-python-select-records-and-export-map2pdf/m-p/269227#M2836</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Original User: christi_nelson&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;pdf is attached&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;PS - I am running ArcGIS 10.0&amp;nbsp; (ArcInfo level)&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 Feb 2013 13:39:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/help-python-select-records-and-export-map2pdf/m-p/269227#M2836</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2013-02-11T13:39:39Z</dc:date>
    </item>
    <item>
      <title>Re: HELP!python select records and export map2PDF</title>
      <link>https://community.esri.com/t5/mapping-questions/help-python-select-records-and-export-map2pdf/m-p/269228#M2837</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I determined that my SQL statement in my whereclause was incorrect.&amp;nbsp; I added a couple of print statements to troubleshoot and was successfully able to change and run it.&amp;nbsp; Here is the corrected whereClause (SQL statement).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;for row in rows: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print row.getValue('APN_NU_1') &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; APN = row.getValue('APN_NU_1') &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "||" + APN + "||" &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; whereClause = "APN_NU_1 = '" + APN + "'" &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "|" + whereClause + "|" &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management(parcelLayer, "NEW_SELECTION", whereClause)&amp;nbsp; &lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm still not sure why I didn't have to make a feature layer before my selection, but I did figure out what the True/False means in the layer.getSelectedExtent(True) means:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;getSelectedExtent ({symbolized_extent})&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;A value of True will return the layer's symbolized extent; otherwise, it will return the geometric extent. The symbolized extent takes into account the area the symbology covers so that it does not get cut off by the data frame's boundary.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;(The default value is True)&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 Feb 2013 17:22:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/help-python-select-records-and-export-map2pdf/m-p/269228#M2837</guid>
      <dc:creator>ChristiNelson1</dc:creator>
      <dc:date>2013-02-11T17:22:25Z</dc:date>
    </item>
  </channel>
</rss>

