Hi everyone,
Im trying to update the layer data sources in a map with the layer data sources in an another map based off name, both maps in the same project (SDE connection, two different databases). Ive been using the jupyter notebook, and have been successful in comparing the layers list to find matches, however when it comes to using the updateConnectionPropertiesfunction in an IDE nothing happens, original project as well as project copy have no changed data sources.
I have tried multiple parameter formats, calling the lyr.connectionProperties as well as creating file paths.
import arcpy
# find original layers in old map service map
aprx = arcpy.mp.ArcGISProject("CURRENT")
m = aprx.listMaps("New Service")[0];
original_layers = m.listLayers()
print(str(len(original_layers)))
# find new layers in new map service map
m2 = aprx.listMaps("New Layer Data Sources")[0];
new_layers = m2.listLayers()
# create empty list to view names that match
success_match = list()
# create empty list to view names that don't match
fail_match = list()
# loop through layers in old map service
for lyr in original_layers:
# if not a group layer then find would be new name
if not lyr.isGroupLayer:
old_name = lyr.dataSource
old_name_split = old_name.split("__")
new_name1 = old_name_split[1]
print(new_name1)
# create variable for old connection properties
old_desc = arcpy.Describe(lyr)
old_data_path = old_desc.path
old_data_source = "r" + "'" + str(old_data_path) + "/" + lyr.name + "'"
# create for loop to loop through new names
for lyr2 in new_layers:
# isolate new layer name to match with original name
full_new_name = lyr2.name
full_new_name_split = full_new_name.split("_")
new_name2 = full_new_name_split[1]
# create variable for new connnection
new_desc = arcpy.Describe(lyr2)
new_data_path = new_desc.path
new_data_source = "r" + "'" + str(new_data_path) + "/" + lyr2.name + "'"
# if old layer new name is equal to new layer name, then chance data source
if new_name1 == new_name2:
success_match.append(new_name2)
lyr.updateConnectionProperties(lyr.connectionProperties, lyr2.connectionProperties)
# if old layer does not match new name layers
if new_name1 not in success_match:
fail_match.append(new_name1)
print(len(success_match))
print(len(fail_match))Any advice would be greatly appreciated. Thank you!