Remove featureDataset attribute from layer CIM connection properties

632
1
Jump to solution
12-03-2020 09:22 AM
Marshal
New Contributor III

Hello Everyone, first post.  Thanks for being a great community.

I am trying to update layer connection properties in an ArcGIS Pro project with arcpy.  The feature classes were formerly in a feature dataset in a file geodatabase.  Now they are in the same file geodatabase, but no feature dataset.

I have seen how the feature dataset can be updated using layer CIM, but I haven't figured out how to completely remove the feature dataset attribute to fix the broken data sources that no longer reside in a feature dataset.

Is this possible?

Thank you!

Marshal

 

 

0 Kudos
1 Solution

Accepted Solutions
Marshal
New Contributor III

I found a solution, although there may be an easier way to directly remove the feature dataset attribute from a layer's CIM dataConnection properties.

I created a template aprx with layer that has the desired connection properties, other than the feature class name.  I will use this template aprx/layer to create CIM dataConnection properties, update the feature class name, and then apply to the broken layers.

I believe I can scale this logic to iterate through all my broken projects and fix the broken data connections.  Please note, this works in my specific case because all my datasets have the same feature class name and same file geodatabase as the broken layers (only needed to remove feature dataset).  If you need to change other attributes, additional code will be required.

Here is the code that worked for me.  Hope this helps someone!

 

# Get connection properties from template project/layer with corrected data connection
template_aprx = arcpy.mp.ArcGISProject(r'P:\GIS\PROJECTS\TEMPLATE\FIX_DATASOURCE.aprx')
template_map = template_aprx.listMaps()[0]
template_lyr = template_map.listLayers('FIXED_LAYER')[0]
templateCIM = template_lyr.getDefinition('V2')
template_dc = templateCIM.featureTable.dataConnection

# Fix all broken data connections in current project using template connection properties
aprx = arcpy.mp.ArcGISProject('CURRENT')
map = aprx.listMaps()[0]
layers = map.listLayers()

for lyr in layers:
    if lyr.isFeatureLayer:
        if lyr.isBroken:
            print('Updating {} layer'.format(lyr))
            source = lyr.dataSource
            fc_name = source.split('\\')[-1]
            template_dc.dataset = fc_name
            layerCIM = lyr.getDefinition('V2')
            layerCIM.featureTable.dataConnection = template_dc
            lyr.setDefinition(layerCIM)

 

 

View solution in original post

1 Reply
Marshal
New Contributor III

I found a solution, although there may be an easier way to directly remove the feature dataset attribute from a layer's CIM dataConnection properties.

I created a template aprx with layer that has the desired connection properties, other than the feature class name.  I will use this template aprx/layer to create CIM dataConnection properties, update the feature class name, and then apply to the broken layers.

I believe I can scale this logic to iterate through all my broken projects and fix the broken data connections.  Please note, this works in my specific case because all my datasets have the same feature class name and same file geodatabase as the broken layers (only needed to remove feature dataset).  If you need to change other attributes, additional code will be required.

Here is the code that worked for me.  Hope this helps someone!

 

# Get connection properties from template project/layer with corrected data connection
template_aprx = arcpy.mp.ArcGISProject(r'P:\GIS\PROJECTS\TEMPLATE\FIX_DATASOURCE.aprx')
template_map = template_aprx.listMaps()[0]
template_lyr = template_map.listLayers('FIXED_LAYER')[0]
templateCIM = template_lyr.getDefinition('V2')
template_dc = templateCIM.featureTable.dataConnection

# Fix all broken data connections in current project using template connection properties
aprx = arcpy.mp.ArcGISProject('CURRENT')
map = aprx.listMaps()[0]
layers = map.listLayers()

for lyr in layers:
    if lyr.isFeatureLayer:
        if lyr.isBroken:
            print('Updating {} layer'.format(lyr))
            source = lyr.dataSource
            fc_name = source.split('\\')[-1]
            template_dc.dataset = fc_name
            layerCIM = lyr.getDefinition('V2')
            layerCIM.featureTable.dataConnection = template_dc
            lyr.setDefinition(layerCIM)