<?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: Find and replace text for all map documents within a folder (mxd) in Mapping Questions</title>
    <link>https://community.esri.com/t5/mapping-questions/find-and-replace-text-for-all-map-documents-within/m-p/581859#M6376</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Original User: jscheirer&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;for mxdFile in mxdList:
&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd = arcpy.mapping.MapDocument(mxdFile)
&amp;nbsp;&amp;nbsp;&amp;nbsp; for elm in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT"):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if elm.text == "works":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; elm.text = "replaceword"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd.save()&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Dec 2021 01:01:08 GMT</pubDate>
    <dc:creator>Anonymous User</dc:creator>
    <dc:date>2021-12-12T01:01:08Z</dc:date>
    <item>
      <title>Find and replace text for all map documents within a folder (mxd)</title>
      <link>https://community.esri.com/t5/mapping-questions/find-and-replace-text-for-all-map-documents-within/m-p/581858#M6375</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Original User: mthorpe&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hello.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm looking to use a Python script to update the text on multiple mxds without opening each one up. Basically a find and replace function, looped through all MXDs in a directory. I have no real Python experience, so perhaps this has a simple answer. This is the code I have right now.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;import arcpy, glob, os&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;path = r"C:\\" &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;mxdList = glob.glob(path + "\*.mxd")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;for mxd in mxdList:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; for elm in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT"):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; if elm.text == "works":&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; elm.text = "replaceword"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;mxd.save()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;del mxd&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The error I am receiving now is "Runtime error &amp;lt;type 'exceptions.AttributeError'&amp;gt;: 'str' object has no attribute '_arc_object'"&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 Feb 2012 19:28:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/find-and-replace-text-for-all-map-documents-within/m-p/581858#M6375</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2012-02-21T19:28:26Z</dc:date>
    </item>
    <item>
      <title>Re: Find and replace text for all map documents within a folder (mxd)</title>
      <link>https://community.esri.com/t5/mapping-questions/find-and-replace-text-for-all-map-documents-within/m-p/581859#M6376</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Original User: jscheirer&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;for mxdFile in mxdList:
&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd = arcpy.mapping.MapDocument(mxdFile)
&amp;nbsp;&amp;nbsp;&amp;nbsp; for elm in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT"):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if elm.text == "works":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; elm.text = "replaceword"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd.save()&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 01:01:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/find-and-replace-text-for-all-map-documents-within/m-p/581859#M6376</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-12-12T01:01:08Z</dc:date>
    </item>
    <item>
      <title>Re: Find and replace text for all map documents within a folder (mxd)</title>
      <link>https://community.esri.com/t5/mapping-questions/find-and-replace-text-for-all-map-documents-within/m-p/581860#M6377</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Bumping this thread because I can get this script to work ... but not perfectly.&amp;nbsp;&amp;nbsp; &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Instead of looping through every MXD in the folder and changing the specified text (changing "Township" to "Borough"), the script only changes the text in the last MXD in the list and saves it.&amp;nbsp; The folder has about 20 MXD's within it but only the last one is edited.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any ideas why only the last MXD would be changed?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Apr 2013 18:54:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/find-and-replace-text-for-all-map-documents-within/m-p/581860#M6377</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2013-04-03T18:54:52Z</dc:date>
    </item>
    <item>
      <title>Re: Find and replace text for all map documents within a folder (mxd)</title>
      <link>https://community.esri.com/t5/mapping-questions/find-and-replace-text-for-all-map-documents-within/m-p/581861#M6378</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Ok, instead of using trying to edit the aforementioned code to get it to work ... I used this instead:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy import os import glob&amp;nbsp; folder = r"\\sample\sample"&amp;nbsp; oldtext = "Township" newtext = "Borough"&amp;nbsp; mxds = glob.glob(folder + '\\' + '*.mxd') arcpy.gp.overwriteOutput = True for mxdFile in mxds: &amp;nbsp;&amp;nbsp;&amp;nbsp; mxd = arcpy.mapping.MapDocument(mxdFile) &amp;nbsp;&amp;nbsp;&amp;nbsp; for elm in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT"): &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if elm.text == oldtext: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; elm.text = newtext &amp;nbsp;&amp;nbsp;&amp;nbsp; mxd.save() del mxd &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Did exactly what I wanted it to do. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 Apr 2013 18:23:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/find-and-replace-text-for-all-map-documents-within/m-p/581861#M6378</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2013-04-08T18:23:53Z</dc:date>
    </item>
    <item>
      <title>Re: Find and replace text for all map documents within a folder (mxd)</title>
      <link>https://community.esri.com/t5/mapping-questions/find-and-replace-text-for-all-map-documents-within/m-p/581862#M6379</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Original User: weltiar&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you wanted to do this dynamically how would the code be changed?&amp;nbsp; I want to create a tool where you can pick what folder and type in old text and the new text.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 03 Jul 2014 19:22:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/find-and-replace-text-for-all-map-documents-within/m-p/581862#M6379</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2014-07-03T19:22:31Z</dc:date>
    </item>
    <item>
      <title>Re: Find and replace text for all map documents within a folder (mxd)</title>
      <link>https://community.esri.com/t5/mapping-questions/find-and-replace-text-for-all-map-documents-within/m-p/581863#M6380</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You could add a script to a toolbox and make a script tool out of it.&amp;nbsp; You would have to make 3 parameters in the tool, one for the input folder(make it a folder type), one for the input text(make it a string type) and one for the output text (make it a string type)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You would have to replace &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;folder = r"\\sample\sample"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;oldtext = "Township"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;newtext = "Borough"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;with &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;folder = arcpy.GetParameterAsText(0)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;oldtext = arcpy.GetParameterAsText(1)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;newtext = arcpy.GetParameterAsText(2)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The 0, 1, 2 pull the first, second, and third parameters you make respectively in the script tool.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Check out &lt;/SPAN&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.1/index.html#/Adding_a_script_tool/00150000001r000000/"&gt;this link&lt;/A&gt;&lt;SPAN&gt; on how to make a script tool.&amp;nbsp; It also has links for setting up the parameters.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 03 Jul 2014 20:36:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/find-and-replace-text-for-all-map-documents-within/m-p/581863#M6380</guid>
      <dc:creator>IanMurray</dc:creator>
      <dc:date>2014-07-03T20:36:15Z</dc:date>
    </item>
  </channel>
</rss>

