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