cim_lyr.featureTable.fieldDescriptions returns an empty list

5198
13
Jump to solution
04-12-2021 02:29 PM
MarvisKisakye1
Regular Contributor

Why would cim_lyr.featureTable.fieldDescriptions return an empty list when the feature layer clearly contains fields? @JeffBarrette @JeffMoulds 

Tags (2)
13 Replies
AaronDutch
New Contributor

It seems that altering the Shape field alias no longer generates the CIM which is frustrating. Following this workflow all of my CIM objects are still empty when using print(cim_obj.featureTable.fieldDescriptions) even though in the APRX the alias has been changed. 

0 Kudos
julian_svcs
Frequent Contributor

@AaronDutch That is strange. I just tested this using ArcGIS Pro 3.0 and it works as expected. I read the fieldDescriptions before changing the alias and it is empty (as expected). When I use AlterField to change the SHAPE field alias and then call the fieldDescriptions again, I get the field details.

Here is my sample code that worked for me:

aprx = arcpy.mp.ArcGISProject("CURRENT")
m = aprx.listMaps(aprx.activeMap.name)[0]
for lyr in m.listLayers():
    if lyr.isFeatureLayer:
        print(f"{lyr.longName}")
        arcpy.AlterField_management(lyr, "SHAPE", new_field_alias="Shape")
        cim_lyr = lyr.getDefinition('V2')
        print(cim_lyr.featureTable.fieldDescriptions)
        for fd in cim_lyr.featureTable.fieldDescriptions:
            print(f"Field Name: {fd.fieldName}")
Pascal
by
New Contributor

Hey all,

thanks for the thread which already helped me a lot when I encountered the empty list.

As I aim to build a Python tool that can change the fieldDescription of a selected layer, I needed to modify the layer with arcpy.AlterField_management() from inside the tool.

Unfortunately, the CIM fieldDescription list is still empty after running the tool. In contrast, If I do the AlterField operation from the Python Window in ArcGIS Pro, the fieldDescription list is getting populated.

Does anyone have an idea how that could be and how the execution of a function from either Python Window or Python Toolbox differs?

Using ArcGIS Pro 3.0.3

Thanks!

PhilLarkin1
Frequent Contributor

I experience the same issue when running Pro 3.2.0. When running AlterField in a geoprocessing script tool, fieldDescription is not being populated. When running in the Python Window it is.  @JeffBarrette