<?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: Data Driven Page Text Element in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/data-driven-page-text-element/m-p/354379#M27863</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks for the help Jeff.&amp;nbsp; I've added an activation of the data driven pages in the code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;#Reference the Data Driven Page object
ddp = mxd.dataDrivenPages
pageNum = mxd.dataDrivenPages.currentPageID&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I've also added a query to the cursor to isolate the map number:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;mapLyr.definitionQuery = '[MAP_NUMBER_FM] = %s' % pageNum
queryExp = '[MAP_NUMBER_FM] = %s' % pageNum
rows = arcpy.SearchCursor(mapLyr.dataSource, queryExp, "")
row = rows.next()&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;That does seem to work with setting the definition query for my table layer.&amp;nbsp; However, when I scroll to a new ddp and run the script, the query doesn't refresh.&amp;nbsp; For example, I ran the script with the ddp pageNum = 1 and the query was set in the related "Permits_final" layer as MAP_NUMBER_FM = 1.&amp;nbsp; When, I advanced to another page and ran the script again, the query/map_number was still set to 1, although the ddp pageNum was 2.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for your help.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 16:37:07 GMT</pubDate>
    <dc:creator>andreagriffith</dc:creator>
    <dc:date>2021-12-11T16:37:07Z</dc:date>
    <item>
      <title>Data Driven Page Text Element</title>
      <link>https://community.esri.com/t5/python-questions/data-driven-page-text-element/m-p/354377#M27861</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm using a combination of data driven pages and a python script to populate text elements on a layout. I have a project set up with an index layer, and a mask layer.&amp;nbsp; I also have a third layer (permits), which I have set up as a page definition query, to match the index layer selected (they both have a map_number field). This works as I scroll through the pages, the permits layer updates to show only those permits within the active page.&amp;nbsp; I would like for those queried permits to then populate a table made up of two text elements. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Now, when I run though the script, the text elements are populated but not with correct information.&amp;nbsp; As I change pages, and the queried permits change, I cannot get the related text elements to change/update.&amp;nbsp; All the rows will show in the text element(s), and not the queried ones only. What am I missing here?&amp;nbsp; I'm not sure if it is a definition query problem or a cursor problem (or neither of these)?&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy

# get the reference to the map document
mxd = arcpy.mapping.MapDocument("Current")

#Reference appropriate data frames
operationsDF = arcpy.mapping.ListDataFrames(mxd, "Operations")[0]
locatorDF = arcpy.mapping.ListDataFrames (mxd, "Locator Map")[0]

#Reference appropriate data layers
mapLyr = arcpy.mapping.ListLayers(mxd, "Permits_final", operationsDF)[0]

# get the reference to the text elements in the map document.
for elm in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT"):
&amp;nbsp;&amp;nbsp;&amp;nbsp; if elm.name == "FacNameelem": FacNameelem = elm
&amp;nbsp;&amp;nbsp;&amp;nbsp; if elm.name == "Stateelem": Stateelem = elm

#Clear all text element values
FacNameelem.text = ' '
Stateelem.text = ' '

# create a cursor and grab the rows in the feature class for the layer specified above
rows = arcpy.SearchCursor(mapLyr.dataSource)
row = rows.next()
text1Value = ""
text2Value = ""
for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp; text1Value +=row.getValue("FACILITY") +"\n"&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; FacNameelem.text = text1Value
&amp;nbsp;&amp;nbsp;&amp;nbsp; text2Value +=row.getValue("State") +"\n"
&amp;nbsp;&amp;nbsp;&amp;nbsp; Stateelem.text = text2Value
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
#Refresh map
arcpy.RefreshActiveView()
 
# save the map document and delete the reference to the row, cursor and map object
mxd.save()
del mxd, row, rows&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 Mar 2013 20:32:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/data-driven-page-text-element/m-p/354377#M27861</guid>
      <dc:creator>andreagriffith</dc:creator>
      <dc:date>2013-03-20T20:32:11Z</dc:date>
    </item>
    <item>
      <title>Re: Data Driven Page Text Element</title>
      <link>https://community.esri.com/t5/python-questions/data-driven-page-text-element/m-p/354378#M27862</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;A couple of things.&amp;nbsp; First, I'm not seeing in the code below where you are driving the DDP pages.&amp;nbsp; Your script needs to advance each DDP page, perform the custom logic, then continue onto the next page.&amp;nbsp; DDP from the UI can't call custom code.&amp;nbsp; You must write a script that drives both DDP along with your custom logic.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Second,&amp;nbsp; your cursor needs to include a query that isolates that particular map_number.&amp;nbsp; For example, &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
rows = arcpy.SearchCursor(mapLyr.dataSource, "/"map_number/" = "101NW")
&lt;/PRE&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 16:37:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/data-driven-page-text-element/m-p/354378#M27862</guid>
      <dc:creator>JeffBarrette</dc:creator>
      <dc:date>2021-12-11T16:37:04Z</dc:date>
    </item>
    <item>
      <title>Re: Data Driven Page Text Element</title>
      <link>https://community.esri.com/t5/python-questions/data-driven-page-text-element/m-p/354379#M27863</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks for the help Jeff.&amp;nbsp; I've added an activation of the data driven pages in the code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;#Reference the Data Driven Page object
ddp = mxd.dataDrivenPages
pageNum = mxd.dataDrivenPages.currentPageID&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I've also added a query to the cursor to isolate the map number:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;mapLyr.definitionQuery = '[MAP_NUMBER_FM] = %s' % pageNum
queryExp = '[MAP_NUMBER_FM] = %s' % pageNum
rows = arcpy.SearchCursor(mapLyr.dataSource, queryExp, "")
row = rows.next()&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;That does seem to work with setting the definition query for my table layer.&amp;nbsp; However, when I scroll to a new ddp and run the script, the query doesn't refresh.&amp;nbsp; For example, I ran the script with the ddp pageNum = 1 and the query was set in the related "Permits_final" layer as MAP_NUMBER_FM = 1.&amp;nbsp; When, I advanced to another page and ran the script again, the query/map_number was still set to 1, although the ddp pageNum was 2.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for your help.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 16:37:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/data-driven-page-text-element/m-p/354379#M27863</guid>
      <dc:creator>andreagriffith</dc:creator>
      <dc:date>2021-12-11T16:37:07Z</dc:date>
    </item>
    <item>
      <title>Re: Data Driven Page Text Element</title>
      <link>https://community.esri.com/t5/python-questions/data-driven-page-text-element/m-p/354380#M27864</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Actually, I have gotten the query to update properly!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I still have one problem - the search cursor is missing a row (the first row). Or should I say the text element is updating with the selected rows, but leaving one out (the first row).&amp;nbsp; For example, I have 10 selected features in the queried layer but only 9 showing related in the text element. I must have something written incorrectly.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for the help!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 23 Mar 2013 20:22:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/data-driven-page-text-element/m-p/354380#M27864</guid>
      <dc:creator>andreagriffith</dc:creator>
      <dc:date>2013-03-23T20:22:28Z</dc:date>
    </item>
  </channel>
</rss>

