It turns out the problem is with the layer grouping.
I ran the following code:
arpx = arcpy.mp.ArcGISProject("CURRENT")
thismap = arpx.activeMap
for layr in thismap.listLayers():
try:
longname = layr.longName
desc = arcpy.Describe(layr)
dty = desc.dataType
messages.addMessage(f"{longname} Type: {dty}")
lyrCIM = layr.getDefinition('V2')
layr.setDefinition(lyrCIM)
messages.addMessage(f"CIM saved")
except Exception as ex10:
messages.addMessage(f"Error: {ex10}")
Which produced the (partial) output:
Flooding\Flooding Information from Council\Upper South Creek Flood Study 2017 - Camden Council\20 Year ARI Type: FeatureLayer
Error:
Flooding\Flooding Information from Council\Upper South Creek Flood Study 2017 - Camden Council\50 Year ARI Type: FeatureLayer
Error:
Flooding\Flooding Information from Council\Upper South Creek Flood Study 2017 - Camden Council\100 Year ARI Type: FeatureLayer
Error:
Flooding\Flooding Information from Council\Upper South Creek Flood Study 2017 - Camden Council\200 Year ARI Type: FeatureLayer
Error:
Flooding\Flooding Information from Council\Upper South Creek Flood Study 2017 - Camden Council\500 Year ARI Type: FeatureLayer
Error:
Flooding\Flooding Information from Council\Upper South Creek Flood Study 2017 - Camden Council\PMF Type: FeatureLayer
CIM saved
As you can see, only one layer (PMF) was able to save the CIM. The rest produced a non-existent error.
I had a look at the 100 Year ARI .lyrx file and there didn't seem to be anything wrong with it.
I removed the above layers from their groups and re-ran the code:
100 Year ARI Type: FeatureLayer
CIM saved
50 Year ARI Type: FeatureLayer
CIM saved
200 Year ARI Type: FeatureLayer
CIM saved
500 Year ARI Type: FeatureLayer
CIM saved
PMF Type: FeatureLayer
CIM saved
All the CIM data was able to be saved.
This does pose some interesting questions though. I wonder if ESRI could shed some light on it.