Select to view content in your preferred language

updateConnectionProperties | Correct Path | Broken layer connection

284
1
03-14-2023 02:49 AM
RutgerDujardin
Emerging Contributor

Hi,

I'm trying as well to use the updateConnectionProperties function. Just in its most basic form, linking a new file geodatabase to an existing .aprx. Old and new databases have exactly the same structure. In my case, the function changes correctly the path's within the .aprx file. But when I open the .aprx it gives my only broken layer connections. When I click the red-exclamation mark and direct to exactly the same location/feature class it retrieves the data.

My question: Why does the red-exclamation mark appears if the path is set correctly? Why can't the .aprx file represent the data when opening it?

The code I'm using:

aprx = arcpy.mp.ArcGISProject(path_Template_aprxFile)

aprx.updateConnectionProperties(None, path_newDatabase)

aprx.saveACopy(path_New_aprxFile)

If anyone can help solving my problem, be welcome.

0 Kudos
1 Reply
RutgerDujardin
Emerging Contributor

I never managed to get the general "updateConnectionProperties" to work. Below the strategy that I finaly applied. An update of the connectionProperties per feature layer:

aprx = arcpy.mp.ArcGISProject(path_Template_aprxFile)

for m in aprx.listMaps():

for layer in m.listLayers():
newCP = layer.connectionProperties
newCP['connection_info']['database'] = path_newDatabase
layer.updateConnectionProperties(layer.connectionProperties, newCP)
aprx.saveACopy(path_New_aprxFile

0 Kudos