<?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 data source of layer in ArcGIS Pro Project using ArcPy in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/changing-data-source-of-layer-in-arcgis-pro/m-p/1128185#M63305</link>
    <description>&lt;P&gt;I have an ArcGIS Pro Project containing layers that have shapefiles as sources. I wrote a script using ArcPy to convert this data to File Geodatabases. Everything works fine here without any issues.&amp;nbsp;&lt;/P&gt;&lt;P&gt;The next step I want to take is replace the data sources of the same layers that I exported, so that they will be referencing the new file location in the File GDB. The best (and only?) way to replace the data source and dataset name is to use &lt;A href="https://resources.arcgis.com/en/help/main/10.1/index.html#/Layer/00s300000008000000/" target="_self"&gt;Layer.replaceDataSource&lt;/A&gt;&amp;nbsp;. But when I use this Layer method, I get this error:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;AttributeError: 'Layer' object has no attribute 'replaceDataSource'&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is because replaceDataSource is a method found only in arcpy.mapping's Layer class. In other words, I'd need to use an ArcMap map document to utilize this method, instead of Pro. Is there a way to do this using arcpy.mp library? Are there any other ways to achieve what I'm trying to do in ArcGIS Pro with ArcPy?&lt;/P&gt;&lt;P&gt;Thank you for the help!&lt;/P&gt;</description>
    <pubDate>Tue, 21 Dec 2021 22:54:43 GMT</pubDate>
    <dc:creator>KevinCheriyan</dc:creator>
    <dc:date>2021-12-21T22:54:43Z</dc:date>
    <item>
      <title>Changing data source of layer in ArcGIS Pro Project using ArcPy</title>
      <link>https://community.esri.com/t5/python-questions/changing-data-source-of-layer-in-arcgis-pro/m-p/1128185#M63305</link>
      <description>&lt;P&gt;I have an ArcGIS Pro Project containing layers that have shapefiles as sources. I wrote a script using ArcPy to convert this data to File Geodatabases. Everything works fine here without any issues.&amp;nbsp;&lt;/P&gt;&lt;P&gt;The next step I want to take is replace the data sources of the same layers that I exported, so that they will be referencing the new file location in the File GDB. The best (and only?) way to replace the data source and dataset name is to use &lt;A href="https://resources.arcgis.com/en/help/main/10.1/index.html#/Layer/00s300000008000000/" target="_self"&gt;Layer.replaceDataSource&lt;/A&gt;&amp;nbsp;. But when I use this Layer method, I get this error:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;AttributeError: 'Layer' object has no attribute 'replaceDataSource'&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is because replaceDataSource is a method found only in arcpy.mapping's Layer class. In other words, I'd need to use an ArcMap map document to utilize this method, instead of Pro. Is there a way to do this using arcpy.mp library? Are there any other ways to achieve what I'm trying to do in ArcGIS Pro with ArcPy?&lt;/P&gt;&lt;P&gt;Thank you for the help!&lt;/P&gt;</description>
      <pubDate>Tue, 21 Dec 2021 22:54:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/changing-data-source-of-layer-in-arcgis-pro/m-p/1128185#M63305</guid>
      <dc:creator>KevinCheriyan</dc:creator>
      <dc:date>2021-12-21T22:54:43Z</dc:date>
    </item>
    <item>
      <title>Re: Changing data source of layer in ArcGIS Pro Project using ArcPy</title>
      <link>https://community.esri.com/t5/python-questions/changing-data-source-of-layer-in-arcgis-pro/m-p/1128200#M63307</link>
      <description>&lt;P&gt;sounds like&amp;nbsp;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/mapping/updatingandfixingdatasources.htm" target="_blank"&gt;Updating and fixing data sources—ArcGIS Pro | Documentation&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;eg&amp;nbsp;&lt;SPAN&gt;updateConnectionProperties&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Dec 2021 00:09:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/changing-data-source-of-layer-in-arcgis-pro/m-p/1128200#M63307</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2021-12-22T00:09:32Z</dc:date>
    </item>
    <item>
      <title>Re: Changing data source of layer in ArcGIS Pro Project using ArcPy</title>
      <link>https://community.esri.com/t5/python-questions/changing-data-source-of-layer-in-arcgis-pro/m-p/1128204#M63308</link>
      <description>&lt;P&gt;As Dan mentioned this function should work.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def remap_arcgis_pro(source_aprx, target_aprx, source_sde_conn, target_sde_conn):
    arcpy.AddMessage("Remapping ArcGIS Pro...")
    aprx = arcpy.mp.ArcGISProject(source_aprx)
    aprx.updateConnectionProperties(current_connection_info=source_sde_conn,
                                    new_connection_info=target_sde_conn)
    aprx.saveACopy(target_aprx)
    return target_aprx&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Dec 2021 00:43:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/changing-data-source-of-layer-in-arcgis-pro/m-p/1128204#M63308</guid>
      <dc:creator>AzinSharaf</dc:creator>
      <dc:date>2021-12-22T00:43:39Z</dc:date>
    </item>
    <item>
      <title>Re: Changing data source of layer in ArcGIS Pro Project using ArcPy</title>
      <link>https://community.esri.com/t5/python-questions/changing-data-source-of-layer-in-arcgis-pro/m-p/1128374#M63315</link>
      <description>&lt;P&gt;I'm saving the Pro Project, but not using saveACopy(), but updateConnectionProperties doesn't seem to work. I'm updating the connectionProperties dict and replacing the original with the new dict. Any ideas on how or what to fix?&lt;/P&gt;&lt;LI-CODE lang="python"&gt;aprx = arcpy.mp.ArcGISProject(project_path)
for mp in aprx.listMaps("Map Name 1"):
     for lyr in mp.listLayers():
          # export out to file geodatabase with new name
          cp = lyr.connectionProperties
          cp['connection_info']['database'] = output_db #output db path+name
          cp['dataset'] = lyr_longName
          lyr.updateConnectionProperties(lyr.connectionProperties, cp)

aprx.save()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Dec 2021 17:40:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/changing-data-source-of-layer-in-arcgis-pro/m-p/1128374#M63315</guid>
      <dc:creator>KevinCheriyan</dc:creator>
      <dc:date>2021-12-22T17:40:36Z</dc:date>
    </item>
    <item>
      <title>Re: Changing data source of layer in ArcGIS Pro Project using ArcPy</title>
      <link>https://community.esri.com/t5/python-questions/changing-data-source-of-layer-in-arcgis-pro/m-p/1128385#M63316</link>
      <description>&lt;P&gt;why &lt;EM&gt;updateConnectionProperties&lt;/EM&gt; on aprx file (not lyr)&amp;nbsp; didn't work?&lt;/P&gt;&lt;P&gt;in your code print(lyr) in the for loop to see which lyr is&amp;nbsp; making problem. I am guessing it doesn't like Esri basemap layers.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Dec 2021 18:13:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/changing-data-source-of-layer-in-arcgis-pro/m-p/1128385#M63316</guid>
      <dc:creator>AzinSharaf</dc:creator>
      <dc:date>2021-12-22T18:13:43Z</dc:date>
    </item>
    <item>
      <title>Re: Changing data source of layer in ArcGIS Pro Project using ArcPy</title>
      <link>https://community.esri.com/t5/python-questions/changing-data-source-of-layer-in-arcgis-pro/m-p/1128420#M63317</link>
      <description>&lt;P&gt;You have to use &lt;STRONG&gt;saveAs&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/mapping/layer-class.htm" target="_blank"&gt;Layer—ArcGIS Pro | Documentation&lt;/A&gt;&amp;nbsp; and updateConnectionProperties is a method of layers in both incarnations.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Dec 2021 19:22:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/changing-data-source-of-layer-in-arcgis-pro/m-p/1128420#M63317</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2021-12-22T19:22:57Z</dc:date>
    </item>
    <item>
      <title>Re: Changing data source of layer in ArcGIS Pro Project using ArcPy</title>
      <link>https://community.esri.com/t5/python-questions/changing-data-source-of-layer-in-arcgis-pro/m-p/1128421#M63318</link>
      <description>&lt;P&gt;I had a break statement in the look to stop the loop after the first layer, and had already removed the base layers...&lt;/P&gt;&lt;P&gt;I think the issue was that the data source on Pro's layers weren't getting updated in the Pro instance I had open. Once I closed it, ran the script, opened it back up again, it works as it should. Must have been just a lock issue.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Dec 2021 19:30:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/changing-data-source-of-layer-in-arcgis-pro/m-p/1128421#M63318</guid>
      <dc:creator>KevinCheriyan</dc:creator>
      <dc:date>2021-12-22T19:30:16Z</dc:date>
    </item>
    <item>
      <title>Re: Changing data source of layer in ArcGIS Pro Project using ArcPy</title>
      <link>https://community.esri.com/t5/python-questions/changing-data-source-of-layer-in-arcgis-pro/m-p/1128436#M63320</link>
      <description>&lt;P&gt;I used save() instead of saveACopy() so that I can work with the same aprx file. Seems to work fine with save() after some troubleshooting now. If any issues, pop back up, I'll have to try the saveACopy() method instead, which I believe is what you're suggesting. Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 22 Dec 2021 20:04:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/changing-data-source-of-layer-in-arcgis-pro/m-p/1128436#M63320</guid>
      <dc:creator>KevinCheriyan</dc:creator>
      <dc:date>2021-12-22T20:04:55Z</dc:date>
    </item>
    <item>
      <title>Re: Changing data source of layer in ArcGIS Pro Project using ArcPy</title>
      <link>https://community.esri.com/t5/python-questions/changing-data-source-of-layer-in-arcgis-pro/m-p/1128526#M63328</link>
      <description>&lt;P&gt;saveACopy prevents disasterous overwrites... disk space is cheap&lt;/P&gt;</description>
      <pubDate>Thu, 23 Dec 2021 02:00:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/changing-data-source-of-layer-in-arcgis-pro/m-p/1128526#M63328</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2021-12-23T02:00:54Z</dc:date>
    </item>
    <item>
      <title>Re: Changing data source of layer in ArcGIS Pro Project using ArcPy</title>
      <link>https://community.esri.com/t5/python-questions/changing-data-source-of-layer-in-arcgis-pro/m-p/1128632#M63333</link>
      <description>&lt;P&gt;You're absolutely right. A million things that could go wrong, and I don't want to mess up my original Project file.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Dec 2021 15:24:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/changing-data-source-of-layer-in-arcgis-pro/m-p/1128632#M63333</guid>
      <dc:creator>KevinCheriyan</dc:creator>
      <dc:date>2021-12-23T15:24:02Z</dc:date>
    </item>
    <item>
      <title>Re: Changing data source of layer in ArcGIS Pro Project using ArcPy</title>
      <link>https://community.esri.com/t5/python-questions/changing-data-source-of-layer-in-arcgis-pro/m-p/1128650#M63334</link>
      <description>&lt;P&gt;apparently not right enough&lt;/P&gt;</description>
      <pubDate>Thu, 23 Dec 2021 16:09:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/changing-data-source-of-layer-in-arcgis-pro/m-p/1128650#M63334</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2021-12-23T16:09:49Z</dc:date>
    </item>
    <item>
      <title>Re: Changing data source of layer in ArcGIS Pro Project using ArcPy</title>
      <link>https://community.esri.com/t5/python-questions/changing-data-source-of-layer-in-arcgis-pro/m-p/1324537#M68507</link>
      <description>&lt;P&gt;Any timeline on when the `.save()` function will be repaired?&lt;/P&gt;</description>
      <pubDate>Thu, 31 Aug 2023 19:55:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/changing-data-source-of-layer-in-arcgis-pro/m-p/1324537#M68507</guid>
      <dc:creator>uasdev</dc:creator>
      <dc:date>2023-08-31T19:55:14Z</dc:date>
    </item>
  </channel>
</rss>

