<?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: How to access dynamic text with arcpy in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-to-access-dynamic-text-with-arcpy/m-p/1553534#M73111</link>
    <description>&lt;P&gt;try this, The datetime.now().strftime("%B %d, %Y") part formats the current date. The element text is set to include the dynamic date tag &amp;lt;dyn type="date" format="MMMM d, yyyy"/&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;import arcpy
from datetime import datetime

# Access the ArcGIS Pro project
aprx = arcpy.mp.ArcGISProject("CURRENT")

# Get the current date in the desired format
current_date = datetime.now().strftime("%B %d, %Y")

# Loop through the layouts and text elements
for lyt in aprx.listLayouts():
    for elm in lyt.listElements('TEXT_ELEMENT'):
        if elm.name == "PrintDate":
            # Update the text element with the dynamic date
            elm.text = f"Print Date: &amp;lt;dyn type=\"date\" format=\"MMMM d, yyyy\"/&amp;gt;"
            #elm.text = '&amp;lt;dyn type="date" format="YYYY-MM-DD"/&amp;gt;'
            print(f'Updated {elm.name} to {elm.text}')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 29 Oct 2024 20:49:00 GMT</pubDate>
    <dc:creator>TonyAlmeida</dc:creator>
    <dc:date>2024-10-29T20:49:00Z</dc:date>
    <item>
      <title>How to access dynamic text with arcpy</title>
      <link>https://community.esri.com/t5/python-questions/how-to-access-dynamic-text-with-arcpy/m-p/1553437#M73105</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JaredPilbeam2_0-1730227010773.png" style="width: 623px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/118375iCCB4EE902117BC29/image-dimensions/623x323?v=v2" width="623" height="323" role="button" title="JaredPilbeam2_0-1730227010773.png" alt="JaredPilbeam2_0-1730227010773.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to automate updates to the dynamic date in a Pro 3.3.2 map document. The dynamic date is in a text element named PrintDate. I can access the element, but not the date. Things I've tried:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;for lyt in aprx.listLayouts():
    for elm in lyt.listElements('TEXT_ELEMENT'):
        if elm.text.endswith("2024"):
            print(f'{elm.name} | {elm.text}') #prints out the one other element in the document with 2024, not the dynamic date
        elif elm.name == "PrintDate":
            print(f'{elm.name} | {elm.text}') #prints out the whole text element with the dynamic date format&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm not after making the date un-dynamic as there are dozens of maps with this set-up. Anyone have an idea?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Oct 2024 18:45:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-access-dynamic-text-with-arcpy/m-p/1553437#M73105</guid>
      <dc:creator>JaredPilbeam2</dc:creator>
      <dc:date>2024-10-29T18:45:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to access dynamic text with arcpy</title>
      <link>https://community.esri.com/t5/python-questions/how-to-access-dynamic-text-with-arcpy/m-p/1553534#M73111</link>
      <description>&lt;P&gt;try this, The datetime.now().strftime("%B %d, %Y") part formats the current date. The element text is set to include the dynamic date tag &amp;lt;dyn type="date" format="MMMM d, yyyy"/&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;import arcpy
from datetime import datetime

# Access the ArcGIS Pro project
aprx = arcpy.mp.ArcGISProject("CURRENT")

# Get the current date in the desired format
current_date = datetime.now().strftime("%B %d, %Y")

# Loop through the layouts and text elements
for lyt in aprx.listLayouts():
    for elm in lyt.listElements('TEXT_ELEMENT'):
        if elm.name == "PrintDate":
            # Update the text element with the dynamic date
            elm.text = f"Print Date: &amp;lt;dyn type=\"date\" format=\"MMMM d, yyyy\"/&amp;gt;"
            #elm.text = '&amp;lt;dyn type="date" format="YYYY-MM-DD"/&amp;gt;'
            print(f'Updated {elm.name} to {elm.text}')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Oct 2024 20:49:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-access-dynamic-text-with-arcpy/m-p/1553534#M73111</guid>
      <dc:creator>TonyAlmeida</dc:creator>
      <dc:date>2024-10-29T20:49:00Z</dc:date>
    </item>
  </channel>
</rss>

