<?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 data source - solution in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/change-data-source-solution/m-p/50692#M4005</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;any help??&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 22 Jan 2015 15:13:04 GMT</pubDate>
    <dc:creator>Raphael_Augusto_FoscariniFerre</dc:creator>
    <dc:date>2015-01-22T15:13:04Z</dc:date>
    <item>
      <title>Change data source - solution</title>
      <link>https://community.esri.com/t5/python-questions/change-data-source-solution/m-p/50691#M4004</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have in my job several MXDs (more than 500) and each one is different from another.&lt;/P&gt;&lt;P&gt;There is one specific shapefile (project_area_03-jan-2015.shp) that every map uses.&lt;/P&gt;&lt;P&gt;The big problem: Every week, the shapefile changes, and also changes the name of the shapefile:&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;project_area_03-jan-2015 means its the 3rd week of january 2015&lt;/P&gt;&lt;P&gt;project_area_04-jan-2015 means its the 3th week of january 2015, and goes forever.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For our actual projects, we changed the way we built the mxds and the shapefiles, so we dont have any problems.&lt;/P&gt;&lt;P&gt;But for this specific old (very old, before 2008), we still have the old architecture of the files.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Every week, we make a copy to another folder and open all +500 MXDs, then 'change data source' in that shapefile, to the new one.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;We tried to use 'MapDocument.findAndReplaceWorkspacePaths' python, but it changes only the path. We need a script to change the entire path from the shapefile.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want some help, that ghanges the shapefiles for me, in all MXDs inside the folder, like;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;from&amp;nbsp; d:\projectalpha\project_area_03-jan-2015.shp&amp;nbsp; to&amp;nbsp; d:\projectalpha\project_area_04-jan-2015.shp&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 Jan 2015 19:39:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/change-data-source-solution/m-p/50691#M4004</guid>
      <dc:creator>Raphael_Augusto_FoscariniFerre</dc:creator>
      <dc:date>2015-01-20T19:39:33Z</dc:date>
    </item>
    <item>
      <title>Re: Change data source - solution</title>
      <link>https://community.esri.com/t5/python-questions/change-data-source-solution/m-p/50692#M4005</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;any help??&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 22 Jan 2015 15:13:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/change-data-source-solution/m-p/50692#M4005</guid>
      <dc:creator>Raphael_Augusto_FoscariniFerre</dc:creator>
      <dc:date>2015-01-22T15:13:04Z</dc:date>
    </item>
    <item>
      <title>Re: Change data source - solution</title>
      <link>https://community.esri.com/t5/python-questions/change-data-source-solution/m-p/50693#M4006</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Raphael,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I believe what you want to use is the &lt;STRONG&gt;replaceDataSource &lt;/STRONG&gt;method off of the &lt;A href="http://resources.arcgis.com/en/help/main/10.2/00s3/00s300000008000000.htm"&gt;Layer &lt;/A&gt;class.&amp;nbsp; This method should allow you to change the name of the layer file serving as the datasource for the layer in your MXDs.&amp;nbsp; Below is some sample code to help you get started.&amp;nbsp; I added {} bracket placeholders to describe the actual values that should be used.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;import arcpy&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;mxd = arcpy.mapping.MapDocument(r"C:\Project\Project.mxd")&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;for lyr in arcpy.mapping.ListLayers(mxd):&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if lyr.supports("DATASOURCE"):&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if lyr.dataSource == r"&lt;EM&gt;{Full path to old layer file}&lt;/EM&gt;&lt;STRONG&gt;\&lt;/STRONG&gt;&lt;EM&gt;{Layer name in layer file}&lt;/EM&gt;":&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr.replaceDataSource(r"&lt;EM&gt;{Full path to new layer file}&lt;/EM&gt;", "NONE", "&lt;EM&gt;{Layer name in layer file}&lt;/EM&gt;")&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;mxd.save()&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good luck!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 22 Jan 2015 16:01:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/change-data-source-solution/m-p/50693#M4006</guid>
      <dc:creator>ErinBrimhall</dc:creator>
      <dc:date>2015-01-22T16:01:48Z</dc:date>
    </item>
  </channel>
</rss>

