<?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: How to &amp;quot;Set Data Source&amp;quot; for a layer using arcpy? in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/how-to-quot-set-data-source-quot-for-a-layer-using/m-p/1390925#M79777</link>
    <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/714367"&gt;@uasdev&lt;/a&gt;&amp;nbsp;I haven't personally done this but a long time back someone suggested me this course:&amp;nbsp;&lt;A href="https://www.esri.com/training/catalog/6361614a4b223839523bc32b/python-scripting-repairing-data-sources/" target="_blank"&gt;https://www.esri.com/training/catalog/6361614a4b223839523bc32b/python-scripting-repairing-data-sources/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Maybe this helps?&lt;/P&gt;</description>
    <pubDate>Tue, 05 Mar 2024 05:06:05 GMT</pubDate>
    <dc:creator>GeeteshSingh07</dc:creator>
    <dc:date>2024-03-05T05:06:05Z</dc:date>
    <item>
      <title>How to "Set Data Source" for a layer using arcpy?</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/how-to-quot-set-data-source-quot-for-a-layer-using/m-p/1390831#M79766</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;I am trying to Set Data Source... using arcpy. This is required for my project, as I need to loop through many layers/project files.&lt;/P&gt;&lt;P&gt;Here is a simplified example of my code:&lt;/P&gt;&lt;P&gt;```&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;import&lt;/SPAN&gt; &lt;SPAN&gt;arcpy&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;os&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;layerName&lt;/SPAN&gt; &lt;SPAN&gt;=&lt;/SPAN&gt; &lt;SPAN&gt;'Site'&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;# old data source&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;# old_data_source = r'C:\path\to\Old.gdb\RealEstate\Site'&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;# new data source&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;new_data_source&lt;/SPAN&gt; &lt;SPAN&gt;=&lt;/SPAN&gt; &lt;SPAN&gt;r&lt;/SPAN&gt;&lt;SPAN&gt;'C:&lt;/SPAN&gt;&lt;SPAN&gt;\p&lt;/SPAN&gt;&lt;SPAN&gt;ath&lt;/SPAN&gt;&lt;SPAN&gt;\t&lt;/SPAN&gt;&lt;SPAN&gt;o&lt;/SPAN&gt;&lt;SPAN&gt;\N&lt;/SPAN&gt;&lt;SPAN&gt;ew.gdb&lt;/SPAN&gt;&lt;SPAN&gt;\R&lt;/SPAN&gt;&lt;SPAN&gt;ealEstate\Site'&lt;/SPAN&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;SPAN&gt;aprx&lt;/SPAN&gt; &lt;SPAN&gt;=&lt;/SPAN&gt; &lt;SPAN&gt;arcpy&lt;/SPAN&gt;&lt;SPAN&gt;.mp.ArcGISProject(&lt;/SPAN&gt;&lt;SPAN&gt;r&lt;/SPAN&gt;&lt;SPAN&gt;'Current'&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;SPAN&gt;for&lt;/SPAN&gt; &lt;SPAN&gt;m&lt;/SPAN&gt; &lt;SPAN&gt;in&lt;/SPAN&gt; &lt;SPAN&gt;aprx&lt;/SPAN&gt;&lt;SPAN&gt;.listMaps():&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;for&lt;/SPAN&gt; &lt;SPAN&gt;lyr&lt;/SPAN&gt; &lt;SPAN&gt;in&lt;/SPAN&gt; &lt;SPAN&gt;m&lt;/SPAN&gt;&lt;SPAN&gt;.listLayers():&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;if&lt;/SPAN&gt; &lt;SPAN&gt;lyr&lt;/SPAN&gt;&lt;SPAN&gt;.supports(&lt;/SPAN&gt;&lt;SPAN&gt;"DATASOURCE"):&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;if&lt;/SPAN&gt; &lt;SPAN&gt;lyr&lt;/SPAN&gt;&lt;SPAN&gt;.longName &lt;/SPAN&gt;&lt;SPAN&gt;==&lt;/SPAN&gt; &lt;SPAN&gt;layerName&lt;/SPAN&gt;&lt;SPAN&gt;:&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;lyr&lt;/SPAN&gt;&lt;SPAN&gt;.updateConnectionProperties(&lt;/SPAN&gt;&lt;SPAN&gt;lyr&lt;/SPAN&gt;&lt;SPAN&gt;.dataSource, &lt;/SPAN&gt;&lt;SPAN&gt;new_data_source&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;```&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I have seen in other posts to use connectionProperties of the lyr. But this requires alot of fine tuning to deal with different types of files (from geodatabase, to shapefile, to kml files).&lt;/DIV&gt;&lt;DIV&gt;Is there a simple way to Set Data Source using arcpy, as one would do simply using the GUI:&lt;/DIV&gt;&lt;DIV&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="uasdev_0-1709595591222.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/96832iAF68C332D8D19CB4/image-size/medium?v=v2&amp;amp;px=400" role="button" title="uasdev_0-1709595591222.png" alt="uasdev_0-1709595591222.png" /&gt;&lt;/span&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Mon, 04 Mar 2024 23:41:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/how-to-quot-set-data-source-quot-for-a-layer-using/m-p/1390831#M79766</guid>
      <dc:creator>uasdev</dc:creator>
      <dc:date>2024-03-04T23:41:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to "Set Data Source" for a layer using arcpy?</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/how-to-quot-set-data-source-quot-for-a-layer-using/m-p/1390925#M79777</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/714367"&gt;@uasdev&lt;/a&gt;&amp;nbsp;I haven't personally done this but a long time back someone suggested me this course:&amp;nbsp;&lt;A href="https://www.esri.com/training/catalog/6361614a4b223839523bc32b/python-scripting-repairing-data-sources/" target="_blank"&gt;https://www.esri.com/training/catalog/6361614a4b223839523bc32b/python-scripting-repairing-data-sources/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Maybe this helps?&lt;/P&gt;</description>
      <pubDate>Tue, 05 Mar 2024 05:06:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/how-to-quot-set-data-source-quot-for-a-layer-using/m-p/1390925#M79777</guid>
      <dc:creator>GeeteshSingh07</dc:creator>
      <dc:date>2024-03-05T05:06:05Z</dc:date>
    </item>
  </channel>
</rss>

