<?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 Update Data Connection with CIM Changes Dictionary but not Feature Source in TOC in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/update-data-connection-with-cim-changes-dictionary/m-p/1501311#M85225</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Updating data connections through the CIM seems to have different recipes with different use cases.&amp;nbsp; In this current case, I am trying change data sources for multiple layers in multiple maps in multiple projects wherein the &lt;STRONG&gt;path/to/gdb a&lt;/STRONG&gt;nd the&amp;nbsp;&lt;STRONG&gt;feature dataset&amp;nbsp;&lt;/STRONG&gt;change &lt;STRONG&gt;(feature class&lt;/STRONG&gt;&amp;nbsp;remains the same in this case).&lt;/P&gt;&lt;P&gt;So change source to a new geodatabase in a new folder, with a new feature dataset.&lt;/P&gt;&lt;P&gt;For the below example, the lyrCIM object updates the dictionary and retains it, yet the layer in the TOC does not change.&lt;/P&gt;&lt;P&gt;i.e. &lt;STRONG&gt;lyrCIM.featureTable.dataConnection&amp;nbsp;&lt;/STRONG&gt;will reflect my changes when I inspect (print) the properties&amp;nbsp;&lt;STRONG&gt;featureDataset&lt;/STRONG&gt;,&amp;nbsp;&lt;STRONG&gt;worskpaceConnectionString&lt;/STRONG&gt;,etc.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# Specify the new geodatabase properties
newGDB =r'path\to\new\whatever.gdb'
origGDB = r'path\to\original\whatever.gdb'
newFeatureClass = r'land_ownership'
# original Feature Dataset was something else
newFeatureDataSet = r'mapping'

# Reference project, map and layer 
fp_aprx = r"path/to/pro_project.aprx"
p = arcpy.mp.ArcGISProject(fp_aprx)
m = p.listMaps('layer_name')[0]
l = m.listLayers('map_name')[0]

# Get the layer's CIM definition
lyrCIM = l.getDefinition('V3')         

dc = lyrCIM.featureTable.dataConnection
dc.workspaceConnectionString = f'DATABASE={newGDB}'
# Note that the name is the same, but this will vary by case
dc.dataset = newFeatureClass

# If the data is in a Feature Dataset, then update it 
if hasattr(dc, "featureDataset"):
    dc.featureDataset = newFeatureDataSet

l.setDefinition(lyrCIM)
p.saveACopy(fp_aprx)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This code was basically verbatim from here&amp;nbsp;&lt;A title="Updating and Fixing Data Sources" href="https://pro.arcgis.com/en/pro-app/latest/arcpy/mapping/updatingandfixingdatasources.htm" target="_self"&gt;Using the CIM to change a layer's dataset&lt;/A&gt;&amp;nbsp; (#3, under subtitle displayed in link; towards bottom of page).&amp;nbsp; I also tried #4 to no avail.&lt;/P&gt;&lt;P&gt;Note that I have had success in the past&amp;nbsp;&lt;A title="previous post" href="https://community.esri.com/t5/arcgis-pro-questions/batch-update-data-source-in-pro-map-python-cim/td-p/1243405" target="_self"&gt;My previous post with updating source within same gdb&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there no programmatic solution to my situation?&lt;/P&gt;&lt;P&gt;v.3.0.2&lt;/P&gt;</description>
    <pubDate>Wed, 03 Jul 2024 21:34:30 GMT</pubDate>
    <dc:creator>ZacharyUhlmann1</dc:creator>
    <dc:date>2024-07-03T21:34:30Z</dc:date>
    <item>
      <title>Update Data Connection with CIM Changes Dictionary but not Feature Source in TOC</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/update-data-connection-with-cim-changes-dictionary/m-p/1501311#M85225</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Updating data connections through the CIM seems to have different recipes with different use cases.&amp;nbsp; In this current case, I am trying change data sources for multiple layers in multiple maps in multiple projects wherein the &lt;STRONG&gt;path/to/gdb a&lt;/STRONG&gt;nd the&amp;nbsp;&lt;STRONG&gt;feature dataset&amp;nbsp;&lt;/STRONG&gt;change &lt;STRONG&gt;(feature class&lt;/STRONG&gt;&amp;nbsp;remains the same in this case).&lt;/P&gt;&lt;P&gt;So change source to a new geodatabase in a new folder, with a new feature dataset.&lt;/P&gt;&lt;P&gt;For the below example, the lyrCIM object updates the dictionary and retains it, yet the layer in the TOC does not change.&lt;/P&gt;&lt;P&gt;i.e. &lt;STRONG&gt;lyrCIM.featureTable.dataConnection&amp;nbsp;&lt;/STRONG&gt;will reflect my changes when I inspect (print) the properties&amp;nbsp;&lt;STRONG&gt;featureDataset&lt;/STRONG&gt;,&amp;nbsp;&lt;STRONG&gt;worskpaceConnectionString&lt;/STRONG&gt;,etc.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# Specify the new geodatabase properties
newGDB =r'path\to\new\whatever.gdb'
origGDB = r'path\to\original\whatever.gdb'
newFeatureClass = r'land_ownership'
# original Feature Dataset was something else
newFeatureDataSet = r'mapping'

# Reference project, map and layer 
fp_aprx = r"path/to/pro_project.aprx"
p = arcpy.mp.ArcGISProject(fp_aprx)
m = p.listMaps('layer_name')[0]
l = m.listLayers('map_name')[0]

# Get the layer's CIM definition
lyrCIM = l.getDefinition('V3')         

dc = lyrCIM.featureTable.dataConnection
dc.workspaceConnectionString = f'DATABASE={newGDB}'
# Note that the name is the same, but this will vary by case
dc.dataset = newFeatureClass

# If the data is in a Feature Dataset, then update it 
if hasattr(dc, "featureDataset"):
    dc.featureDataset = newFeatureDataSet

l.setDefinition(lyrCIM)
p.saveACopy(fp_aprx)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This code was basically verbatim from here&amp;nbsp;&lt;A title="Updating and Fixing Data Sources" href="https://pro.arcgis.com/en/pro-app/latest/arcpy/mapping/updatingandfixingdatasources.htm" target="_self"&gt;Using the CIM to change a layer's dataset&lt;/A&gt;&amp;nbsp; (#3, under subtitle displayed in link; towards bottom of page).&amp;nbsp; I also tried #4 to no avail.&lt;/P&gt;&lt;P&gt;Note that I have had success in the past&amp;nbsp;&lt;A title="previous post" href="https://community.esri.com/t5/arcgis-pro-questions/batch-update-data-source-in-pro-map-python-cim/td-p/1243405" target="_self"&gt;My previous post with updating source within same gdb&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there no programmatic solution to my situation?&lt;/P&gt;&lt;P&gt;v.3.0.2&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jul 2024 21:34:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/update-data-connection-with-cim-changes-dictionary/m-p/1501311#M85225</guid>
      <dc:creator>ZacharyUhlmann1</dc:creator>
      <dc:date>2024-07-03T21:34:30Z</dc:date>
    </item>
    <item>
      <title>Re: Update Data Connection CIM</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/update-data-connection-with-cim-changes-dictionary/m-p/1501354#M85232</link>
      <description>&lt;P&gt;I Found a solution thanks to the bread crumbs from this post&amp;nbsp;&lt;A title="Using updateConnectionProperties to update a single layer with ArcPy" href="https://community.esri.com/t5/arcgis-pro-questions/using-updateconnectionproperties-to-update-a/m-p/1501337#M85230" target="_self"&gt;Using updateConnectionProperties to update a single layer with ArcPy&lt;/A&gt;&amp;nbsp;.&amp;nbsp; It appears to be a bug.&amp;nbsp; To circumvent it, do this:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;aprx = arcpy.mp.ArcGISProject('current')
# Then do all the exact same dataConnection updates and save with the path
fp_aprx = 'path/to/project.aprx'
aprx.saveACopy(fp_aprx)&lt;/LI-CODE&gt;&lt;P&gt;So, basically just load the aprx object using the argument,&amp;nbsp;&lt;STRONG&gt;"current"&lt;/STRONG&gt;&amp;nbsp;- not&amp;nbsp;&lt;STRONG&gt;"path/to/project.aprx"&lt;/STRONG&gt;.&amp;nbsp; Unsure what's going on, but I can confirm that this solved the problem.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jul 2024 21:32:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/update-data-connection-with-cim-changes-dictionary/m-p/1501354#M85232</guid>
      <dc:creator>ZacharyUhlmann1</dc:creator>
      <dc:date>2024-07-03T21:32:17Z</dc:date>
    </item>
  </channel>
</rss>

