<?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 Updating identical text elements in multiple MXDs in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/updating-identical-text-elements-in-multiple-mxds/m-p/270936#M20947</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, I'm looking to create a python script that will update a folder of mxds together. I have designated 6 TEXT_ELEMENTS in my titleblock to be updated using&amp;nbsp; arcpy.GetParameterAsText()&amp;nbsp; but will just use 1 for this question.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Below is my text for updating the text element if i were to only update one .mxd which as the top line says only edits the current .mxd that is open. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;STRONG&gt;thisMap = arcpy.mapping.MapDocument("CURRENT")&lt;/STRONG&gt;
&lt;STRONG&gt;myDF = arcpy.mapping.ListDataFrames(thisMap) [0]&lt;/STRONG&gt;
&lt;STRONG&gt;myLayers = arcpy.mapping.ListLayers(myDF)&lt;/STRONG&gt;
&lt;STRONG&gt;newProjectTitle = arcpy.GetParameterAsText(0)&lt;/STRONG&gt;
myElements = arcpy.mapping.ListLayoutElements(thisMap, "TEXT_ELEMENT")
for element in myElements:
&amp;nbsp;&amp;nbsp; if element.name == "ProjectTitle":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; element.text = newProjectTitle
arcpy.RefreshActiveView()&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then using a script in a custom toolbox, i can input the new Project title, and it update the MXD. (not very useful yet as i could just click on the text element itself and update it manually)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However i would like to take it further and update not just the current .mxd, but all my .mxds in a specified folder and&amp;nbsp; (using path = arcpy.GetParameterAsText(0))&lt;/P&gt;&lt;P&gt;It will save ample amounts of time as there are projects where i will need to manually open x amount of .mxds to rename a Text element in all of them that has been incorrectly named.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I was wondering if anyone could help me with the python code as im quite new to python and don't know what i am doing: &lt;/P&gt;&lt;P&gt;1)&amp;nbsp;&amp;nbsp; specifying the folder to open &lt;EM&gt;using path = arcpy.GetParameterAsText&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;2)&amp;nbsp; creating a list of all the .mxds in said folder (like below? not sure if this is the best method)&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;iteLog=open(path+"\FileListLog.txt","w")
for fileName in os.listdir(path):
&amp;nbsp;&amp;nbsp;&amp;nbsp; fullPath = os.path.join(path, fileName)
&amp;nbsp;&amp;nbsp;&amp;nbsp; if os.path.isfile(fullPath):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; basename, extension = os.path.splitext(fullPath)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if extension == ".mxd":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; writeLog.write(fullPath+"\n")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd = arcpy.mapping.MapDocument(fullPath)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print fileName + "\n"
del mxd
print "Done"
writeLog.close()&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="line-height: 1.5;"&gt;3)&amp;nbsp; specifying the text_element(s) to be updated&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;4) cycling through (via the script) each .mxd in the list and updating the specified text_element, then saving, closing and opening the next on the list. (this would be the main part im confused with)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance and let me know if i haven't provided enough information!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Stef&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 13:14:55 GMT</pubDate>
    <dc:creator>StefKoroblitsas</dc:creator>
    <dc:date>2021-12-11T13:14:55Z</dc:date>
    <item>
      <title>Updating identical text elements in multiple MXDs</title>
      <link>https://community.esri.com/t5/python-questions/updating-identical-text-elements-in-multiple-mxds/m-p/270936#M20947</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, I'm looking to create a python script that will update a folder of mxds together. I have designated 6 TEXT_ELEMENTS in my titleblock to be updated using&amp;nbsp; arcpy.GetParameterAsText()&amp;nbsp; but will just use 1 for this question.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Below is my text for updating the text element if i were to only update one .mxd which as the top line says only edits the current .mxd that is open. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;STRONG&gt;thisMap = arcpy.mapping.MapDocument("CURRENT")&lt;/STRONG&gt;
&lt;STRONG&gt;myDF = arcpy.mapping.ListDataFrames(thisMap) [0]&lt;/STRONG&gt;
&lt;STRONG&gt;myLayers = arcpy.mapping.ListLayers(myDF)&lt;/STRONG&gt;
&lt;STRONG&gt;newProjectTitle = arcpy.GetParameterAsText(0)&lt;/STRONG&gt;
myElements = arcpy.mapping.ListLayoutElements(thisMap, "TEXT_ELEMENT")
for element in myElements:
&amp;nbsp;&amp;nbsp; if element.name == "ProjectTitle":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; element.text = newProjectTitle
arcpy.RefreshActiveView()&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then using a script in a custom toolbox, i can input the new Project title, and it update the MXD. (not very useful yet as i could just click on the text element itself and update it manually)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However i would like to take it further and update not just the current .mxd, but all my .mxds in a specified folder and&amp;nbsp; (using path = arcpy.GetParameterAsText(0))&lt;/P&gt;&lt;P&gt;It will save ample amounts of time as there are projects where i will need to manually open x amount of .mxds to rename a Text element in all of them that has been incorrectly named.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I was wondering if anyone could help me with the python code as im quite new to python and don't know what i am doing: &lt;/P&gt;&lt;P&gt;1)&amp;nbsp;&amp;nbsp; specifying the folder to open &lt;EM&gt;using path = arcpy.GetParameterAsText&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;2)&amp;nbsp; creating a list of all the .mxds in said folder (like below? not sure if this is the best method)&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;iteLog=open(path+"\FileListLog.txt","w")
for fileName in os.listdir(path):
&amp;nbsp;&amp;nbsp;&amp;nbsp; fullPath = os.path.join(path, fileName)
&amp;nbsp;&amp;nbsp;&amp;nbsp; if os.path.isfile(fullPath):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; basename, extension = os.path.splitext(fullPath)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if extension == ".mxd":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; writeLog.write(fullPath+"\n")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd = arcpy.mapping.MapDocument(fullPath)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print fileName + "\n"
del mxd
print "Done"
writeLog.close()&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="line-height: 1.5;"&gt;3)&amp;nbsp; specifying the text_element(s) to be updated&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;4) cycling through (via the script) each .mxd in the list and updating the specified text_element, then saving, closing and opening the next on the list. (this would be the main part im confused with)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance and let me know if i haven't provided enough information!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Stef&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 13:14:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/updating-identical-text-elements-in-multiple-mxds/m-p/270936#M20947</guid>
      <dc:creator>StefKoroblitsas</dc:creator>
      <dc:date>2021-12-11T13:14:55Z</dc:date>
    </item>
  </channel>
</rss>

