<?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: Change Shapefile in a MXD with Python in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/change-shapefile-in-a-mxd-with-python/m-p/88188#M6859</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try changing the data source path &lt;A href="http://desktop.arcgis.com/en/desktop/latest/analyze/arcpy-mapping/updatingandfixingdatasources.htm" title="http://desktop.arcgis.com/en/desktop/latest/analyze/arcpy-mapping/updatingandfixingdatasources.htm"&gt;Updating and fixing data sources with arcpy.mapping—Help | ArcGIS for Desktop&lt;/A&gt;&amp;nbsp; instead of looping through the data frame layers.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 08 Oct 2015 14:41:48 GMT</pubDate>
    <dc:creator>WesMiller</dc:creator>
    <dc:date>2015-10-08T14:41:48Z</dc:date>
    <item>
      <title>Change Shapefile in a MXD with Python</title>
      <link>https://community.esri.com/t5/python-questions/change-shapefile-in-a-mxd-with-python/m-p/88187#M6858</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, i have a simple problem and i think there is a simple solution, but i can find or create it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a lot of MXD (more than 200) and all of them use a polygon shapefile "study_area_v00.shp".&lt;/P&gt;&lt;P&gt;In the data frame, its name is just "Study Area".&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Every time we change the boundary of the polygon, we save a new copy to "study_area_v01.shp" an so on.&lt;/P&gt;&lt;P&gt;All the attributes in table is the same, nothing changes, but the boundary.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Every time we open all the mxd and change the data source, one by one because none of pythons i found, work fine.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This script works fine, and change all the layerfiles in all MXD in a folder.&lt;/P&gt;&lt;P&gt;But there is a little detail in my case: my layer name in table of contents have a word with acccent (&lt;SPAN style="color: #e23d39;"&gt;&lt;STRONG&gt;Á&lt;/STRONG&gt;&lt;/SPAN&gt;rea de Estudo) and the script doesnt recognize it. I translated all the script to all of you understand, but i'm from Brazil and we have a lot of words with accent, and the arcpy doesnt understand it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can you help me?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;SPAN style="font-size: 8pt;"&gt;import arcpy, os&lt;/SPAN&gt;
&lt;SPAN style="font-size: 8pt;"&gt;inputPath = os.curdir&lt;/SPAN&gt;
&lt;SPAN style="font-size: 8pt;"&gt;outputPath = os.curdir&lt;/SPAN&gt;


&lt;SPAN style="font-size: 8pt;"&gt;#layerfile name we want to change, in table of contents&lt;/SPAN&gt;
&lt;SPAN style="font-size: 8pt;"&gt;layerfile = "Área de Estudo"&lt;/SPAN&gt;

&lt;SPAN style="font-size: 8pt;"&gt;#Folder path of the new shapefile&lt;/SPAN&gt;
&lt;SPAN style="font-size: 8pt;"&gt;FolderPath = r"T:\VALE SISTEMA SUL\PDE&amp;nbsp; TREVO\Geoprocessamento\1_Shapefile\Utm"&lt;/SPAN&gt;

&lt;SPAN style="font-size: 8pt;"&gt;#Name of the new shapefile, in folder path (without '.shp')&lt;/SPAN&gt;
&lt;SPAN style="font-size: 8pt;"&gt;NewShapefile = "AreasEstudo_PDETrevo_v00"&lt;/SPAN&gt;


&lt;SPAN style="font-size: 8pt;"&gt;#Loop through each MXD file&lt;/SPAN&gt;
&lt;SPAN style="font-size: 8pt;"&gt;for filename in os.listdir(inputPath):&lt;/SPAN&gt;
&lt;SPAN style="font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; fullpath = os.path.join(inputPath, filename)&lt;/SPAN&gt;
&lt;SPAN style="font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if os.path.isfile(fullpath):&lt;/SPAN&gt;
&lt;SPAN style="font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if filename.lower().endswith(".mxd"):&lt;/SPAN&gt;


&lt;SPAN style="font-size: 8pt;"&gt;&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; &lt;/SPAN&gt;
&lt;SPAN style="font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; df = arcpy.mapping.ListDataFrames(mxd)[0]&amp;nbsp; &lt;/SPAN&gt;
&lt;SPAN style="font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for lyr in arcpy.mapping.ListLayers(mxd, "*", df):&amp;nbsp; &lt;/SPAN&gt;
&lt;SPAN style="font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if lyr.name == layerfile:&amp;nbsp; &lt;/SPAN&gt;
&lt;SPAN style="font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print layerfile&lt;/SPAN&gt;
&lt;SPAN style="font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr.replaceDataSource(FolderPath, "SHAPEFILE_WORKSPACE", NewShapefile)&amp;nbsp; &lt;/SPAN&gt;
&lt;SPAN style="font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print fullpath&amp;nbsp; &lt;/SPAN&gt;
&lt;SPAN style="font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd.save()&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Message was edited by: Dan Patterson
I have taken the liberty to format the post using Syntax highlighting found in the &amp;gt;&amp;gt; option
Hope everything is as you posted.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 23:22:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/change-shapefile-in-a-mxd-with-python/m-p/88187#M6858</guid>
      <dc:creator>Raphael_Augusto_FoscariniFerre</dc:creator>
      <dc:date>2021-12-10T23:22:23Z</dc:date>
    </item>
    <item>
      <title>Re: Change Shapefile in a MXD with Python</title>
      <link>https://community.esri.com/t5/python-questions/change-shapefile-in-a-mxd-with-python/m-p/88188#M6859</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try changing the data source path &lt;A href="http://desktop.arcgis.com/en/desktop/latest/analyze/arcpy-mapping/updatingandfixingdatasources.htm" title="http://desktop.arcgis.com/en/desktop/latest/analyze/arcpy-mapping/updatingandfixingdatasources.htm"&gt;Updating and fixing data sources with arcpy.mapping—Help | ArcGIS for Desktop&lt;/A&gt;&amp;nbsp; instead of looping through the data frame layers.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Oct 2015 14:41:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/change-shapefile-in-a-mxd-with-python/m-p/88188#M6859</guid>
      <dc:creator>WesMiller</dc:creator>
      <dc:date>2015-10-08T14:41:48Z</dc:date>
    </item>
    <item>
      <title>Re: Change Shapefile in a MXD with Python</title>
      <link>https://community.esri.com/t5/python-questions/change-shapefile-in-a-mxd-with-python/m-p/88189#M6860</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I just did a test run with the same layer name and I was able to successfully change the layer name using the following code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;for layer in arcpy.mapping.ListLayers(mxd,"",df):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if layer.name == u'\xc1rea de Estudo':
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; layer.name = "Area de Estudo"&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That being said you could probably set your layerfile = '\xc1rea de Estudo' and your script may work.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 23:22:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/change-shapefile-in-a-mxd-with-python/m-p/88189#M6860</guid>
      <dc:creator>LukeSturtevant</dc:creator>
      <dc:date>2021-12-10T23:22:25Z</dc:date>
    </item>
    <item>
      <title>Re: Change Shapefile in a MXD with Python</title>
      <link>https://community.esri.com/t5/python-questions/change-shapefile-in-a-mxd-with-python/m-p/88190#M6861</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks man! It worked fine!&lt;/P&gt;&lt;P&gt;Thanks a lot!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How can i know about every code that the python will consider my accents? This is just one case!&lt;/P&gt;&lt;P&gt;Is there a dictionay?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;some examples:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;á, é, í, ó, ú&lt;/P&gt;&lt;P&gt;ã õ&lt;/P&gt;&lt;P&gt;â ê&lt;/P&gt;&lt;P&gt;ç&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Oct 2015 16:03:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/change-shapefile-in-a-mxd-with-python/m-p/88190#M6861</guid>
      <dc:creator>Raphael_Augusto_FoscariniFerre</dc:creator>
      <dc:date>2015-10-08T16:03:44Z</dc:date>
    </item>
    <item>
      <title>Re: Change Shapefile in a MXD with Python</title>
      <link>https://community.esri.com/t5/python-questions/change-shapefile-in-a-mxd-with-python/m-p/88191#M6862</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm not too familiar with the codecs so I'm sure someone else could be more informative, but I'm sure you could find something that would be useful at the following sites:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://docs.python.org/2.4/lib/standard-encodings.html" title="https://docs.python.org/2.4/lib/standard-encodings.html"&gt;4.9.2 Standard Encodings&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and the codecs python module:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://docs.python.org/2/library/codecs.html" title="https://docs.python.org/2/library/codecs.html"&gt;7.8. codecs — Codec registry and base classes — Python 2.7.10 documentation&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;you can also use the ord() and unichr() functions. For example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; unichr(ord('Á'))&lt;/P&gt;&lt;P&gt;u'\xc1'&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; unichr(ord('ó'))&lt;/P&gt;&lt;P&gt;u'\xf3'&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;so to find 'Área de Estudo' with python you could concatenate:&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; layerfile = unichr(ord('Á'))+'rea de Estudo'&lt;/P&gt;&lt;P&gt;u'\xc1rea de Estudo'&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;also I found that if you create a list of your accent characters and then return the items it prints how python sees them:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; charList = ['á','é','í','ó','ú','ã','õ','â','ê','ç']&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; charList&lt;/P&gt;&lt;P&gt;['\xe1', '\xe9', '\xed', '\xf3', '\xfa', '\xe3', '\xf5', '\xe2', '\xea', '\xe7']&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So that might also be useful in some cases. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Oct 2015 17:05:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/change-shapefile-in-a-mxd-with-python/m-p/88191#M6862</guid>
      <dc:creator>LukeSturtevant</dc:creator>
      <dc:date>2015-10-08T17:05:30Z</dc:date>
    </item>
    <item>
      <title>Re: Change Shapefile in a MXD with Python</title>
      <link>https://community.esri.com/t5/python-questions/change-shapefile-in-a-mxd-with-python/m-p/88192#M6863</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;thanks a lot, again!!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Oct 2015 17:09:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/change-shapefile-in-a-mxd-with-python/m-p/88192#M6863</guid>
      <dc:creator>Raphael_Augusto_FoscariniFerre</dc:creator>
      <dc:date>2015-10-08T17:09:24Z</dc:date>
    </item>
  </channel>
</rss>

