Select to view content in your preferred language

updateConnection Properties: Switching in and out of Feature Datasets

05-03-2023 08:34 AM
MVP Regular Contributor

Hi all,

I'm running into yet another issue with updateConnectionProperties()

I am trying to switch between example4gdb, which is in a feature dataset, and ex2gdb, which is not.



In this picture, ex2gdb is represented by red triangles with the number 2 in them. example4gdb is represented by green squares with the number 4 in them. The goal is to switch the layers so that ex2gdb displays as green squares and example4gdb draws as red triangles.

I'm struggling with getting it to work correctly.

My most successful approach has been to create a feature layer and copy the connection properties from it onto the layer I'm trying to update.

sourceDict = {r"...test.gdb\testFD\example4gdb" : r"...test.gdb\ex2gdb",
              r"...test.gdb\ex2gdb": r"....test.gdb\testFD\example4gdb"}

for lay in layerFile.listLayers():
    if lay.supports("dataSource"):
        layPath = lay.dataSource
        layPath= arcpy.da.Describe(lay)["catalogPath"]

    if layPath in sourceDict:
        tempLay =[layPath], "tempLay")[0]
        layCP = lay.connectionProperties
        fCP = tempLay.connectionProperties
        lay.updateConnectionProperties(layCP, fCP )

This has the desired effect visually:


However, it doesn't correctly update the actual datasource; the datasources become the following, which very much do not exist:



Consequently, I can't do any other geoprocessing with these layers because the files they reference are not real.

How can I cleanly update connection properties without running into this problem?


0 Kudos
1 Reply
MVP Regular Contributor

I don't want to jinx myself, but I dusted this script off today for the first time in months and this problem seems  to have been resolved since we upgraded to 3.1 from 2.9.


Good news for me, but I have questions now lol.

0 Kudos