Hi. I am organizing a project so that all feature layers used in map and layouts are from the project geodatabase. Initially I had 10 feature classes in the project gdb (easements.gdb) and 10 more split across three other gdbs. They are file Geodatabases. I had no problem copying the feature classes into the project geodatabase, so now all 20 are there - with the same name. Now I am struggling to change the paths of the 10 added FCs to the project geodatabase within the maps. Here is my code:
import copy
current_gdb = r'path/to/current/projet/easements.gdb'
p = arcpy.mp.ArcGISProject('current')
m = p.listMaps('easement_map')[0]
lyrs = [f for f in m.listLayers() if f.isFeatureLayer]
for lyr in lyrs:
cp = lyr.connectionProperties
cp['connection_info']['database']= copy.copy(current_gdb)
# note that dictionary updates properly when printed
print(cp['connection_info']['database'])
lyr.updateConnectionProperties(lyr.connectionProperties, cp)However, lyr does not update
# still prints the old database
print(lyr.connectionProperties)
PRINTS: {'dataset': 'feat_name', 'workspace_factory': 'File Geodatabase', 'connection_info': {'database': 'path/to/original/whatever.gdb'}}
So the layer property dictionary is not updating. I'm baffled - this should work...
Thanks,
Zach