Select to view content in your preferred language

updateConnection Properties: Switching in and out of Feature Datasets

275
1
05-03-2023 08:34 AM
AlfredBaldenweck
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.

AlfredBaldenweck_0-1683126583574.png

AlfredBaldenweck_1-1683127105724.png

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
    else:
        layPath= arcpy.da.Describe(lay)["catalogPath"]

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

This has the desired effect visually:

AlfredBaldenweck_2-1683127292607.png

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

 "...test.gdb\testFD\ex2gdb"

"...test.gdb\example4gdb"

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?

Thanks!

0 Kudos
1 Reply
AlfredBaldenweck
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