<?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 - Using data driven pages to select features from another layer to get attributes to text in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/python-using-data-driven-pages-to-select-features/m-p/114518#M8960</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Delete row/cursor did not work.&amp;nbsp; I also noticed two things, it is just writing the results of the last page on all the pages, not the first page results like I thought.&amp;nbsp; Also while I watch it export each page it is updating the text element in arcmap when it goes to each page while exporting, but not in the pdf. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 08 Jun 2015 18:13:32 GMT</pubDate>
    <dc:creator>deleted-user-MS0lE1F_0-sy</dc:creator>
    <dc:date>2015-06-08T18:13:32Z</dc:date>
    <item>
      <title>Python - Using data driven pages to select features from another layer to get attributes to text</title>
      <link>https://community.esri.com/t5/python-questions/python-using-data-driven-pages-to-select-features/m-p/114512#M8954</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10.5pt; font-family: Helvetica, sans-serif;"&gt;I am trying to loop through exporting data drive pages, select data from another layer based on the page getting exported, and write a row of the results of the selection to a text element.&amp;nbsp; Each page should have different results in text element.&amp;nbsp; For each page getting exported I I want to select all the parcels within the current page/feature getting exported and write the results to the text element.&amp;nbsp; What I have so far only writes the results for the first page on every page.&amp;nbsp; When it runs it does seem to select the parcels per page while exporting, but it does not re-write the results to the text element.&amp;nbsp; Not sure what I am missing?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# Always run script in the mxd you are working on.
mxd = arcpy.mapping.MapDocument("CURRENT")


# Overwrites any existing features.
arcpy.env.overwriteOutput = True


# Uses the Dataframe called "Layers".
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]


# Parcel Text Element
ParcelText2 = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "ParcelsText2")[0]


# Data Driven Pages Export Sheets
ExportSheets = arcpy.mapping.Layer("Sheets_11x17")


# Parcels
Parcels = arcpy.mapping.Layer("Parcels")


# Data Driven Pages mxd abbreviation
ddp = mxd.dataDrivenPages


# Loop through DDP's
for pageNumb in range(1, mxd.dataDrivenPages.pageCount + 1):
&amp;nbsp;&amp;nbsp;&amp;nbsp; ddp.currentPageID = pageNumb


&amp;nbsp;&amp;nbsp;&amp;nbsp; # DDP Export Sheet duplicate which has the page definition Query
&amp;nbsp;&amp;nbsp;&amp;nbsp; SelectedSheet = arcpy.mapping.Layer("Sheets_11x172")


&amp;nbsp;&amp;nbsp;&amp;nbsp; # Exports Row page
&amp;nbsp;&amp;nbsp;&amp;nbsp; ExportSheetsPage = ddp.pageRow.PLAN_NUMBER


&amp;nbsp;&amp;nbsp;&amp;nbsp; # Select Parcels withing my SelectedSheet
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByLocation_management(Parcels, "WITHIN", SelectedSheet)


&amp;nbsp;&amp;nbsp;&amp;nbsp; # Use SearchCursor to get Parcels value and write to Parcel Text Element
&amp;nbsp;&amp;nbsp;&amp;nbsp; rows = arcpy.SearchCursor(Parcels)
&amp;nbsp;&amp;nbsp;&amp;nbsp; textValue = ""
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; textValue += row.getValue("MAP_PARCEL")
&amp;nbsp;&amp;nbsp;&amp;nbsp; ParcelText2.text = textValue


&amp;nbsp;&amp;nbsp;&amp;nbsp; # Export Sheets
&amp;nbsp;&amp;nbsp;&amp;nbsp; ddp.exportToPDF(r"Y:\GIS\GIS_Work\Working\parcel_test\maps\test.mxd")&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 06:47:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-using-data-driven-pages-to-select-features/m-p/114512#M8954</guid>
      <dc:creator>deleted-user-MS0lE1F_0-sy</dc:creator>
      <dc:date>2021-12-11T06:47:03Z</dc:date>
    </item>
    <item>
      <title>Re: Python - Using data driven pages to select features from another layer to get attributes to text</title>
      <link>https://community.esri.com/t5/python-questions/python-using-data-driven-pages-to-select-features/m-p/114513#M8955</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;have you tried deleting your cursor and rows after it set your text element in the loop?&amp;nbsp; If the cursor isn't deleted, it could be using the same cursor each time instead of creating a new one maybe?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also, out of curiousity why are you using the old cursors(arcpy.SearchCursor) instead of the new one arcpy.da.SearchCursor, the new ones are significantly faster.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 Jun 2015 17:10:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-using-data-driven-pages-to-select-features/m-p/114513#M8955</guid>
      <dc:creator>IanMurray</dc:creator>
      <dc:date>2015-06-08T17:10:47Z</dc:date>
    </item>
    <item>
      <title>Re: Python - Using data driven pages to select features from another layer to get attributes to text</title>
      <link>https://community.esri.com/t5/python-questions/python-using-data-driven-pages-to-select-features/m-p/114514#M8956</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Also, please don't double post, you can use the share function to share a single post in more than one area.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/message/392178"&gt;Share a post with a group&lt;/A&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 Jun 2015 17:14:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-using-data-driven-pages-to-select-features/m-p/114514#M8956</guid>
      <dc:creator>IanMurray</dc:creator>
      <dc:date>2015-06-08T17:14:48Z</dc:date>
    </item>
    <item>
      <title>Re: Python - Using data driven pages to select features from another layer to get attributes to text</title>
      <link>https://community.esri.com/t5/python-questions/python-using-data-driven-pages-to-select-features/m-p/114515#M8957</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I will try that.&amp;nbsp; I was playing around with deleting the text element but not the cursor and rows.&amp;nbsp; I will start using da, was just re-diving into an old script and also using what is familiar, time to upgrade my knowledge.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 Jun 2015 17:18:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-using-data-driven-pages-to-select-features/m-p/114515#M8957</guid>
      <dc:creator>deleted-user-MS0lE1F_0-sy</dc:creator>
      <dc:date>2015-06-08T17:18:25Z</dc:date>
    </item>
    <item>
      <title>Re: Python - Using data driven pages to select features from another layer to get attributes to text</title>
      <link>https://community.esri.com/t5/python-questions/python-using-data-driven-pages-to-select-features/m-p/114516#M8958</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sorry about that.&amp;nbsp; It seemed like I could only post in one area.&amp;nbsp; I will not double post in the future.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 Jun 2015 17:19:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-using-data-driven-pages-to-select-features/m-p/114516#M8958</guid>
      <dc:creator>deleted-user-MS0lE1F_0-sy</dc:creator>
      <dc:date>2015-06-08T17:19:50Z</dc:date>
    </item>
    <item>
      <title>Re: Python - Using data driven pages to select features from another layer to get attributes to text</title>
      <link>https://community.esri.com/t5/python-questions/python-using-data-driven-pages-to-select-features/m-p/114517#M8959</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You could do a spatial join and use data driven text to accomplish what you are trying to do.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 Jun 2015 17:38:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-using-data-driven-pages-to-select-features/m-p/114517#M8959</guid>
      <dc:creator>WesMiller</dc:creator>
      <dc:date>2015-06-08T17:38:08Z</dc:date>
    </item>
    <item>
      <title>Re: Python - Using data driven pages to select features from another layer to get attributes to text</title>
      <link>https://community.esri.com/t5/python-questions/python-using-data-driven-pages-to-select-features/m-p/114518#M8960</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Delete row/cursor did not work.&amp;nbsp; I also noticed two things, it is just writing the results of the last page on all the pages, not the first page results like I thought.&amp;nbsp; Also while I watch it export each page it is updating the text element in arcmap when it goes to each page while exporting, but not in the pdf. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 Jun 2015 18:13:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-using-data-driven-pages-to-select-features/m-p/114518#M8960</guid>
      <dc:creator>deleted-user-MS0lE1F_0-sy</dc:creator>
      <dc:date>2015-06-08T18:13:32Z</dc:date>
    </item>
    <item>
      <title>Re: Python - Using data driven pages to select features from another layer to get attributes to text</title>
      <link>https://community.esri.com/t5/python-questions/python-using-data-driven-pages-to-select-features/m-p/114519#M8961</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Spatial join will work in this case, but this is a small part of a larger script where I would run into problems with this.&amp;nbsp; I feel I am very close getting this way to work and would like to continue down this path.&amp;nbsp; I really appreciate the help.&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 Jun 2015 18:16:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-using-data-driven-pages-to-select-features/m-p/114519#M8961</guid>
      <dc:creator>deleted-user-MS0lE1F_0-sy</dc:creator>
      <dc:date>2015-06-08T18:16:34Z</dc:date>
    </item>
    <item>
      <title>Re: Python - Using data driven pages to select features from another layer to get attributes to text</title>
      <link>https://community.esri.com/t5/python-questions/python-using-data-driven-pages-to-select-features/m-p/114520#M8962</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I don't use DDP at all, so I feel like I'm working with one hand behind my back here.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Your parameters for the export to pdf seem odd, the first parameter should be the outpdf name, yet you have a .mxd as the first parameter.&amp;nbsp; Also, I would make sure you are using more parameters, namely you can select the page range and and page range.&amp;nbsp; If you do not change the export parameters, it exports all page each time, not the single page. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 Jun 2015 18:39:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-using-data-driven-pages-to-select-features/m-p/114520#M8962</guid>
      <dc:creator>IanMurray</dc:creator>
      <dc:date>2015-06-08T18:39:11Z</dc:date>
    </item>
    <item>
      <title>Re: Python - Using data driven pages to select features from another layer to get attributes to text</title>
      <link>https://community.esri.com/t5/python-questions/python-using-data-driven-pages-to-select-features/m-p/114521#M8963</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I did not notice the .mxd rather than pdf, but it does not seem to effect it.&amp;nbsp; I appreciate the advice, I think I will play around with my export parameters some. I am thinking about exporting the "current" individual pages then appending them at the end.&amp;nbsp; If you think of anything else please let me know,&amp;nbsp; I will post if I discover the answer and any other things that come up that might help.&amp;nbsp; Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 Jun 2015 19:02:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-using-data-driven-pages-to-select-features/m-p/114521#M8963</guid>
      <dc:creator>deleted-user-MS0lE1F_0-sy</dc:creator>
      <dc:date>2015-06-08T19:02:36Z</dc:date>
    </item>
    <item>
      <title>Re: Python - Using data driven pages to select features from another layer to get attributes to text</title>
      <link>https://community.esri.com/t5/python-questions/python-using-data-driven-pages-to-select-features/m-p/114522#M8964</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Got it to work using your suggestions.&amp;nbsp; Had to create a new pdf document before I ran the loop, export each sheet individually, and append.&amp;nbsp; Thanks for the helping me think it through!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# Always run script in the mxd you are working on.
mxd = arcpy.mapping.MapDocument("CURRENT")
finalResult = arcpy.mapping.PDFDocumentCreate(r"Y:\GIS\GIS_Work\Working\parcel_test\maps\final.pdf")
# Overwrites any existing features.
arcpy.env.overwriteOutput = True
# Uses the Dataframe called "Layers".
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
extent = df.extent
ParcelText2 = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "ParcelsText2")[0]
ExportSheets = arcpy.mapping.Layer("Sheets_11x17")
Parcels = arcpy.mapping.Layer("Parcels")
ddp = mxd.dataDrivenPages
for pageNumb in range(1, mxd.dataDrivenPages.pageCount + 1):
&amp;nbsp;&amp;nbsp;&amp;nbsp; ddp.currentPageID = pageNumb
&amp;nbsp;&amp;nbsp;&amp;nbsp; SelectedSheet = arcpy.mapping.Layer("Sheets_11x172")
&amp;nbsp;&amp;nbsp;&amp;nbsp; ExportSheetsPage = ddp.pageRow.PLAN_NUMBER
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByLocation_management(Parcels, "WITHIN", SelectedSheet)
&amp;nbsp;&amp;nbsp;&amp;nbsp; rows = arcpy.SearchCursor(Parcels)
&amp;nbsp;&amp;nbsp;&amp;nbsp; textValue = ""
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; textValue += row.getValue("MAP_PARCEL")
&amp;nbsp;&amp;nbsp;&amp;nbsp; ParcelText2.text = textValue
&amp;nbsp;&amp;nbsp;&amp;nbsp; del rows
&amp;nbsp;&amp;nbsp;&amp;nbsp; ddp.exportToPDF(r"Y:\GIS\GIS_Work\Working\parcel_test\maps\test.pdf", "CURRENT")
&amp;nbsp;&amp;nbsp;&amp;nbsp; finalResult.appendPages(r"Y:\GIS\GIS_Work\Working\parcel_test\maps\test.pdf")
&amp;nbsp;&amp;nbsp;&amp;nbsp; del textValue&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 06:47:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-using-data-driven-pages-to-select-features/m-p/114522#M8964</guid>
      <dc:creator>deleted-user-MS0lE1F_0-sy</dc:creator>
      <dc:date>2021-12-11T06:47:05Z</dc:date>
    </item>
    <item>
      <title>Re: Python - Using data driven pages to select features from another layer to get attributes to text</title>
      <link>https://community.esri.com/t5/python-questions/python-using-data-driven-pages-to-select-features/m-p/114523#M8965</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I know this is an older post but I think your script could help with something similar I was trying to do.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I want to be able to use Data Driven Pages to give me a list of features from another layer (point) within each page.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Basically, I have a GRID polygon layer with a field called PAGE. PAGE is used for DDP with a range of 1-184.&lt;/P&gt;&lt;P&gt;I also have a point layer called TRAFFIC SIGNS that has a field with unique FACILITY_ID numbers that I use for inventory purposes.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For each PAGE I want to select all the TRAFFIC SIGNS within the page and write out each traffic sign's FACILITY_ID to a text file.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am new to Python so bare with me and thanks for any advice ahead of time!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 Nov 2015 20:57:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-using-data-driven-pages-to-select-features/m-p/114523#M8965</guid>
      <dc:creator>Sergio_Vazquez</dc:creator>
      <dc:date>2015-11-20T20:57:36Z</dc:date>
    </item>
    <item>
      <title>Re: Python - Using data driven pages to select features from another layer to get attributes to text</title>
      <link>https://community.esri.com/t5/python-questions/python-using-data-driven-pages-to-select-features/m-p/114524#M8966</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;#&amp;nbsp; I have the current sheet as a parameter.&amp;nbsp; This is going to be your grid sheet/page.&amp;nbsp; You will need a copy of the layer you are using for data driven pages, open the properties -&amp;gt; Definition Query and set up the Page Definition.
CurrentSheet = arcpy.GetParameterAsText(0)

Selection = arcpy.SelectLayerByLocation_management(TRAFFICSIGNS, "INTERSECT", CurrentSheet)

# TextElement = the Element Name
TextElement.text = Selection

ddp.exportToPDF("C:LOCATION", "CURRENT")
finalResult.appendPages("C:LOCATION")

&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 06:47:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-using-data-driven-pages-to-select-features/m-p/114524#M8966</guid>
      <dc:creator>deleted-user-MS0lE1F_0-sy</dc:creator>
      <dc:date>2021-12-11T06:47:08Z</dc:date>
    </item>
  </channel>
</rss>

