<?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: lyr.replaceDataSource in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/lyr-replacedatasource/m-p/402309#M31686</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I understand how to do it through ArcCatalog and manually, i was trying to do this trough python. The "Subject_property" needs to be updated before the "NOTIFBUF1" because of the processes.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 27 Aug 2015 18:42:09 GMT</pubDate>
    <dc:creator>CCWeedcontrol</dc:creator>
    <dc:date>2015-08-27T18:42:09Z</dc:date>
    <item>
      <title>lyr.replaceDataSource</title>
      <link>https://community.esri.com/t5/python-questions/lyr-replacedatasource/m-p/402302#M31679</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am having issues with lyr.replaceDataSource, I have an mxd that has layers with symbol that i need to just update the layers after some process are ran, there is a few layers i need to update but for some reason it only replace the first lyr.replaceDataSource but after the first one it removes the layer from the TOC, then it adds it back.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The script runs and updates both layers fine if i remove both arcpy.MultipleRingBuffer_analysis (lines 20&amp;amp;21), but when i add it back it does what i described.&lt;/P&gt;&lt;P&gt;Any help would be gratefully appreciated.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy, os

arcpy.env.overwriteOutput = True

mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
lyr = arcpy.mapping.ListLayers(mxd, "SUBJECT_PROPERTY")[0]

arcpy.env.workspace = os.path.dirname(mxd.filePath)
wp = os.path.dirname(mxd.filePath)

SP = "SUBJECT_PROPERTY" 
for lyr in arcpy.mapping.ListLayers(mxd):
&amp;nbsp;&amp;nbsp;&amp;nbsp; if lyr.supports("DATASOURCE"):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if lyr.name == "SUBJECT_PROPERTY":&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(wp, "SHAPEFILE_WORKSPACE", SP, "")

del mxd, lyr

arcpy.MultipleRingBuffer_analysis(SP, "1_2",[1,2],"Miles","ToBufDist","ALL" )
arcpy.MultipleRingBuffer_analysis(SP, "NOTIFBUF1",[600],"Feet","ToBufDist","ALL")

mxd = arcpy.mapping.MapDocument("CURRENT")
lyr = arcpy.mapping.ListLayers(mxd, "NOTIFBUF1")[0]

NF = "NOTIFBUF1"
for lyr in arcpy.mapping.ListLayers(mxd):
&amp;nbsp;&amp;nbsp;&amp;nbsp; if lyr.supports("DATASOURCE"):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if lyr.name == "NOTIFBUF1":&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(wp, "SHAPEFILE_WORKSPACE", NF, "")&amp;nbsp; 
&amp;nbsp; 
#mxd = arcpy.mapping.MapDocument("CURRENT")
#lyr = arcpy.mapping.ListLayers(mxd, "NOTIFBUF1")[0]
#lyr.replaceDataSource(wp, "SHAPEFILE_WORKSPACE", "NOTIFBUF1", True)

arcpy.RefreshActiveView()
arcpy.RefreshTOC()&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 18:20:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/lyr-replacedatasource/m-p/402302#M31679</guid>
      <dc:creator>CCWeedcontrol</dc:creator>
      <dc:date>2021-12-11T18:20:26Z</dc:date>
    </item>
    <item>
      <title>Re: lyr.replaceDataSource</title>
      <link>https://community.esri.com/t5/python-questions/lyr-replacedatasource/m-p/402303#M31680</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;TABLE class="arcpyclass_methodsigtbl" style="margin-bottom: 1.5em; font-size: 0.875em; font-family: 'Lucida Grande', 'Segoe UI', Arial, sans-serif; border: 1px solid #dcdcdc; color: #4d4d4d; background-color: white;"&gt;&lt;TBODY&gt;&lt;TR style="border-bottom-width: 1px; border-bottom-color: #dcdcdc;"&gt;&lt;TD style="border-left-width: 1px; border-left-style: solid; border-left-color: #dcdcdc; border-right-width: 1px; border-right-style: solid; border-right-color: #dcdcdc; padding: 12px;"&gt;replaceDataSource (workspace_path, workspace_type, {dataset_name}, {validate})&lt;/TD&gt;&lt;TD style="border-left-width: 1px; border-left-style: solid; border-left-color: #dcdcdc; border-right-width: 1px; border-right-style: solid; border-right-color: #dcdcdc; padding: 12px;"&gt;&lt;P style="font-size: 0.875rem;"&gt;Replaces a data source for a layer in a map document (&lt;SPAN class="usertext" style="font-family: Consolas, 'Andale Mono', 'Lucida Console', Monaco, 'Courier New', Courier, monospace; font-weight: bold;"&gt;.mxd&lt;/SPAN&gt;) or layer (&lt;SPAN class="usertext" style="font-family: Consolas, 'Andale Mono', 'Lucida Console', Monaco, 'Courier New', Courier, monospace; font-weight: bold;"&gt;.lyr&lt;/SPAN&gt;) file. It also provides the ability to switch workspace types (e.g., replaces a file geodatabase data source with an SDE data source).&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;A href="http://desktop.arcgis.com/en/desktop/latest/analyze/arcpy-mapping/layer-class.htm" title="http://desktop.arcgis.com/en/desktop/latest/analyze/arcpy-mapping/layer-class.htm"&gt;Layer—Help | ArcGIS for Desktop&lt;/A&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Aug 2015 18:04:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/lyr-replacedatasource/m-p/402303#M31680</guid>
      <dc:creator>WesMiller</dc:creator>
      <dc:date>2015-08-27T18:04:36Z</dc:date>
    </item>
    <item>
      <title>Re: lyr.replaceDataSource</title>
      <link>https://community.esri.com/t5/python-questions/lyr-replacedatasource/m-p/402304#M31681</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;When i first open my mxd the layers "Subject_property" &amp;amp; "NOTIFBUFI" data source are not there, it has a red exclamation point. I run the script which creates the "Subject_property" &amp;amp; "NOTIFBUFI" to the mxd folder, then i been trying to use the lyr.replaceDataSource process to set the data source to the newly created "Subject_property" &amp;amp; "NOTIFBUFI". I guess i am confused i should be using something else and why does It works if i remove the two arcpy.MultipleRingBuffer_analysis&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Aug 2015 18:24:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/lyr-replacedatasource/m-p/402304#M31681</guid>
      <dc:creator>CCWeedcontrol</dc:creator>
      <dc:date>2015-08-27T18:24:47Z</dc:date>
    </item>
    <item>
      <title>Re: lyr.replaceDataSource</title>
      <link>https://community.esri.com/t5/python-questions/lyr-replacedatasource/m-p/402305#M31682</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If it's only the one layer, it's easiest to click the red exclamation point and navigate to where the data now lives to repair the broken link.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Aug 2015 18:30:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/lyr-replacedatasource/m-p/402305#M31682</guid>
      <dc:creator>WesMiller</dc:creator>
      <dc:date>2015-08-27T18:30:33Z</dc:date>
    </item>
    <item>
      <title>Re: lyr.replaceDataSource</title>
      <link>https://community.esri.com/t5/python-questions/lyr-replacedatasource/m-p/402306#M31683</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here is some more reading material on broken data links.&lt;/P&gt;&lt;P&gt;&lt;A href="http://support.esri.com/cN/knowledgebase/techarticles/detail/27425" title="http://support.esri.com/cN/knowledgebase/techarticles/detail/27425"&gt;27425 - Use the 'Set Data Source' tool for map documents in ArcCatalog&lt;/A&gt; &lt;/P&gt;&lt;P&gt;&lt;A href="http://desktop.arcgis.com/en/desktop/latest/map/working-with-layers/repairing-broken-data-links.htm" title="http://desktop.arcgis.com/en/desktop/latest/map/working-with-layers/repairing-broken-data-links.htm"&gt;Repairing broken data links—Help | ArcGIS for Desktop&lt;/A&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Aug 2015 18:35:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/lyr-replacedatasource/m-p/402306#M31683</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2015-08-27T18:35:41Z</dc:date>
    </item>
    <item>
      <title>Re: lyr.replaceDataSource</title>
      <link>https://community.esri.com/t5/python-questions/lyr-replacedatasource/m-p/402307#M31684</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The mxd template has four layers that need the datasource updated. I just put two on the script i posted cuz i was trying to figure out what was going on.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Aug 2015 18:38:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/lyr-replacedatasource/m-p/402307#M31684</guid>
      <dc:creator>CCWeedcontrol</dc:creator>
      <dc:date>2015-08-27T18:38:09Z</dc:date>
    </item>
    <item>
      <title>Re: lyr.replaceDataSource</title>
      <link>https://community.esri.com/t5/python-questions/lyr-replacedatasource/m-p/402308#M31685</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If they are all in the same workspace fixing one by clicking the exclamation mark, will fix all. Typically this happens when you move or delete data.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Aug 2015 18:40:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/lyr-replacedatasource/m-p/402308#M31685</guid>
      <dc:creator>WesMiller</dc:creator>
      <dc:date>2015-08-27T18:40:22Z</dc:date>
    </item>
    <item>
      <title>Re: lyr.replaceDataSource</title>
      <link>https://community.esri.com/t5/python-questions/lyr-replacedatasource/m-p/402309#M31686</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I understand how to do it through ArcCatalog and manually, i was trying to do this trough python. The "Subject_property" needs to be updated before the "NOTIFBUF1" because of the processes.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Aug 2015 18:42:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/lyr-replacedatasource/m-p/402309#M31686</guid>
      <dc:creator>CCWeedcontrol</dc:creator>
      <dc:date>2015-08-27T18:42:09Z</dc:date>
    </item>
    <item>
      <title>Re: lyr.replaceDataSource</title>
      <link>https://community.esri.com/t5/python-questions/lyr-replacedatasource/m-p/402310#M31687</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;if i ran the script in ArcMap python window i had to use the arcpy.Delete_management to delete the "NOTIFBUF1" right after the MultipleRingBuffer_analysis becaue it would add a new "NOTIFBUF1". if i didn't i would remove the broken layer from mxd. I ran the same script in a tool script and i did not have to use the Delete_management because it did not remove the layer from the mxd and it updated the broken layer just fine. Interesting findings.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 28 Aug 2015 16:35:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/lyr-replacedatasource/m-p/402310#M31687</guid>
      <dc:creator>CCWeedcontrol</dc:creator>
      <dc:date>2015-08-28T16:35:52Z</dc:date>
    </item>
  </channel>
</rss>

