Why would cim_lyr.featureTable.fieldDescriptions return an empty list when the feature layer clearly contains fields? @JeffBarrette @JeffMoulds
I want to thank you Marvis for sending me your data. I was able to reproduce and then checked in with our CIM experts. I learned something too.
"We only write field descriptions if they differ from the default for that field. Once you make some change (to the field visibility, or alias, or formatting, etc.) to any field, then we populate that entire collection. Doing it this way keeps the layer representation small. Think of them as overrides."
So to get this to work, I simply went into the fields view and changed the visibility of OID. I made it not visible. Then I saved the project and ran the same code and I could see ALL fields.
Jeff - arcpy.mp and Layout teams
I know this is a really old post but I was going through some old emails, etc and came across this thread. I've helped people address this issue (differently than AlterField) and want to paste that code here as an option for people to try.
Basically, if there are NO field descriptions (e.g., a layer was just added), then another option is to use MakeFeatureLayer. The MakeFeatureLayer result has the CIM properties. You make the changes and than copy those changes back to the original layer. There are pre3.4 and 3.4 and beyond options.
def updateCIMFields(l, cimLyr): fList = ["SQKM", "POP2001", "Shape_Length", "Shape_Area"] for fd in cimLyr.featureTable.fieldDescriptions: if fd.fieldName in fList: fd.numberFormat.roundingOption = "esriRoundNumberOfDecimals" fd.numberFormat.roundingValue = 0 fd.numberFormat.zeroPad = True fd.numberFormat.useSeparator = True l.setDefinition(cimLyr) return cimLyr p = arcpy.mp.ArcGISProject('current') m = p.listMaps()[0] lyr = m.listLayers('Provinces')[0] lyr_cim = lyr.getDefinition('V3') if len(lyr_cim.featureTable.fieldDescriptions) == 0: #NO CIM field info present print('No CIM Field Info') mkLyr = arcpy.management.MakeFeatureLayer(lyr)[0] mkLyr_cim = mkLyr.getDefinition('V3') mkLyr_cim = updateCIMFields(mkLyr, mkLyr_cim) #Copy CIM information and remove temporary layer #lyr_cim.featureTable.fieldDescriptions = mkLyr_cim.featureTable.fieldDescriptions ###for 3.3 and prior #lyr.setDefinition(lyr_cim) ###for 3.3 and prior lyr.pasteProperties(mkLyr, 'FIELD_PROPERTIES') ###for 3.4 and prior m.removeLayer(mkLyr) else: #CIM field info present print('CIM Field Info Pre-Exists') lyr_cim = updateCIMFields(lyr, lyr_cim) lyr.setDefinition(lyr_cim)
Jeff - arcpy.mp Team
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
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!
I'm not sure what to say. Does your FC have an attribute table? I just tried the following on a simple polygon layer.
p = arcpy.mp.ArcGISProject('current') m = p.listMaps()[0] l = m.listLayers()[0] c = l.getDefinition('V2') fields = c.featureTable.fieldDescriptions len(fields) 15
You are welcome to send me a layer package to jbarrette@esri.com and I can take a look.
According to property tip in the image above, there is an expectation for an argument for the fieldDescriptions property otherwise it creates an empty list.
p=arcpy.mp.ArcGISProject("current")m=p.listMaps()[0]l=m.listLayers()[0]c=l.getDefinition('V2')fields=c.featureTable.fieldDescriptions
print (fields) prints an empty list.
Marvis,
It shouldn't. Can you supply the few lines of code that grabs the field list?
Membros conectados podem postar, seguir atualizações e mais. Novo aqui? Registre uma conta gratuita.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.