<?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 Changing source data in a layer within an mxd using arcpy.mapping in Mapping Questions</title>
    <link>https://community.esri.com/t5/mapping-questions/changing-source-data-in-a-layer-within-an-mxd/m-p/392892#M4225</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I want to change the source data of a layer within my mxd using arcpy.mapping&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I found something promsing &lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00s30000004p000000" rel="nofollow noopener noreferrer" target="_blank"&gt;here &lt;/A&gt;&lt;SPAN&gt;and &lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Layer/00s300000008000000/" rel="nofollow noopener noreferrer" target="_blank"&gt;here&lt;/A&gt;&lt;SPAN&gt;. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My template layerfile points to "T:\temp_data.gdb\DimensionsFC" and I want to redirect the source to be "T:\temp_data_userid.gdb\DimensionsFC"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I've tried lyr.findAndReplaceWorkspacePaths but it didn't seem to do anything. Here's my code snippet: &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; upLyr = arcpy.mapping.ListLayers(mxd, "Dimensions", df)[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.AddMessage("Dimensions data original : ")
&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.AddMessage(upLyr.dataSource)
&amp;nbsp;&amp;nbsp;&amp;nbsp; # this is the source layer that has the symbology in it
&amp;nbsp;&amp;nbsp;&amp;nbsp; srcLyr = arcpy.mapping.Layer(r"W:\srm\sry\Workarea\land_officers\map_robot\TechieStuff\template_dimensions.lyr")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("updating the Dimensions layer")
&amp;nbsp;&amp;nbsp;&amp;nbsp; # doing the actual layer update here
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.UpdateLayer(df, upLyr, srcLyr, False)
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; oldsrc = upLyr.workspacePath&amp;nbsp; # the old (current) data source

&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr.findAndReplaceWorkspacePath(oldsrc, tmpfgdb)&amp;nbsp; # changing to the user's fgdb

&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.AddMessage(tmpfgdb + ' is my temp fgdb name')
&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.AddMessage("Dimensions data source changed: ")
&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.AddMessage(upLyr.dataSource)
&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.AddMessage(DimFC + ' is my dimensions FC')&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;after doing all that and looking at the "add message" statements it looks like nothing has changed. The mxd's lyr called "Dimensions" still has the original source. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any help please? &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;P.S.: I think there's typo in the example in the first link. probably should not have an "s" at the end of "findAndReplaceWorkspacePaths".&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;When I tried it with the "s" it bombed. But if I used it without the "S" as it's printed in the other help page it seemed to execute without the error.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 18:00:20 GMT</pubDate>
    <dc:creator>JoshuaChan</dc:creator>
    <dc:date>2021-12-11T18:00:20Z</dc:date>
    <item>
      <title>Changing source data in a layer within an mxd using arcpy.mapping</title>
      <link>https://community.esri.com/t5/mapping-questions/changing-source-data-in-a-layer-within-an-mxd/m-p/392892#M4225</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I want to change the source data of a layer within my mxd using arcpy.mapping&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I found something promsing &lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00s30000004p000000" rel="nofollow noopener noreferrer" target="_blank"&gt;here &lt;/A&gt;&lt;SPAN&gt;and &lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Layer/00s300000008000000/" rel="nofollow noopener noreferrer" target="_blank"&gt;here&lt;/A&gt;&lt;SPAN&gt;. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My template layerfile points to "T:\temp_data.gdb\DimensionsFC" and I want to redirect the source to be "T:\temp_data_userid.gdb\DimensionsFC"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I've tried lyr.findAndReplaceWorkspacePaths but it didn't seem to do anything. Here's my code snippet: &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; upLyr = arcpy.mapping.ListLayers(mxd, "Dimensions", df)[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.AddMessage("Dimensions data original : ")
&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.AddMessage(upLyr.dataSource)
&amp;nbsp;&amp;nbsp;&amp;nbsp; # this is the source layer that has the symbology in it
&amp;nbsp;&amp;nbsp;&amp;nbsp; srcLyr = arcpy.mapping.Layer(r"W:\srm\sry\Workarea\land_officers\map_robot\TechieStuff\template_dimensions.lyr")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("updating the Dimensions layer")
&amp;nbsp;&amp;nbsp;&amp;nbsp; # doing the actual layer update here
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.UpdateLayer(df, upLyr, srcLyr, False)
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; oldsrc = upLyr.workspacePath&amp;nbsp; # the old (current) data source

&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr.findAndReplaceWorkspacePath(oldsrc, tmpfgdb)&amp;nbsp; # changing to the user's fgdb

&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.AddMessage(tmpfgdb + ' is my temp fgdb name')
&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.AddMessage("Dimensions data source changed: ")
&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.AddMessage(upLyr.dataSource)
&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.AddMessage(DimFC + ' is my dimensions FC')&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;after doing all that and looking at the "add message" statements it looks like nothing has changed. The mxd's lyr called "Dimensions" still has the original source. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any help please? &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;P.S.: I think there's typo in the example in the first link. probably should not have an "s" at the end of "findAndReplaceWorkspacePaths".&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;When I tried it with the "s" it bombed. But if I used it without the "S" as it's printed in the other help page it seemed to execute without the error.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 18:00:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/changing-source-data-in-a-layer-within-an-mxd/m-p/392892#M4225</guid>
      <dc:creator>JoshuaChan</dc:creator>
      <dc:date>2021-12-11T18:00:20Z</dc:date>
    </item>
    <item>
      <title>Re: Changing source data in a layer within an mxd using arcpy.mapping</title>
      <link>https://community.esri.com/t5/mapping-questions/changing-source-data-in-a-layer-within-an-mxd/m-p/392893#M4226</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;One of my genius co-workers discovered the fix for this. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I had the wrong impression of how UpdateLayer works. The &lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/UpdateLayer/00s30000003p000000/"&gt;UpdateLayer &lt;/A&gt;&lt;SPAN&gt;seems to plunk the "source_layer" into your mxd.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I was trying to change the update layer but it no longer exists in the mxd. So I have to change the source_layer (my .lyr file) with &lt;/SPAN&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;srcLyr.replaceDataSource(tmpfgdb, "FILEGDB_WORKSPACE", "DimensionsFC")&lt;/PRE&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;then the one visible in my mxd will have the correct data source. As long as i don't save, I won't overwrite my original .lyr file (i hope)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;overall, the updateLayer works opposite from what I thought.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 Jan 2012 22:58:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/changing-source-data-in-a-layer-within-an-mxd/m-p/392893#M4226</guid>
      <dc:creator>JoshuaChan</dc:creator>
      <dc:date>2012-01-19T22:58:43Z</dc:date>
    </item>
  </channel>
</rss>

