displayField and displayExpressionInfo are mutually exclusive, i.e., use displayField for displaying a field only and use displayExpressionInfo for displaying an expression. You are passing an expression into displayField, which is why the "$feature" is being prepended.
Thanks a lot, Joshua! That actual worked. I ended up with the following code:
lyr_def = lyr.getDefinition("V2")
exp_info = arcpy.cim.CIMExpressionInfo()
exp_info.expression = "\"Matr. nr. \"+$feature.MatrikelNr+\" \"+$feature.LandsEjerlav+\" (\"+$feature.LandsEjerlavKode+\")\""
lyr_def.featureTable.displayExpressionInfo = exp_info
lyr.setDefinition(lyr_def)
I really appreciate the help 🙂
It isn't supported in arcpy.
There are old threads to this effect
How does ArcMap decide which field is used for the... - GeoNet, The Esri Community
It isn't under arcpy's layer properties or the recent addition of CIM
Python CIM access—ArcGIS Pro | Documentation
I couldn't even find it as an Idea
Hi Dan.
Yeah, I also tried using CIM by setting the displayField property to the required expression. It actually sets it, but it looks strange and doesn't work.
I used this Py code:
lyr_def = lyr.getDefinition("V2")
lyr_def.featureTable.displayField = "\"Matr. nr. \"+$feature.MatrikelNr+\" \"+$feature.LandsEjerlav+\" (\"+$feature.LandsEjerlavKode+\")\""
Which changes it
But for some reason it's adding a $feature. in front of my express. So no luck there. Hopefully this will be added as a possibility in the future.
Thanks for the reply 🙂
$feature .... looks like Arcade to me
displayField and displayExpressionInfo are mutually exclusive, i.e., use displayField for displaying a field only and use displayExpressionInfo for displaying an expression. You are passing an expression into displayField, which is why the "$feature" is being prepended.
Thanks for contributing to this solution. I had the same question and you have saved me a lot of time.
Thanks a lot, Joshua! That actual worked. I ended up with the following code:
lyr_def = lyr.getDefinition("V2")
exp_info = arcpy.cim.CIMExpressionInfo()
exp_info.expression = "\"Matr. nr. \"+$feature.MatrikelNr+\" \"+$feature.LandsEjerlav+\" (\"+$feature.LandsEjerlavKode+\")\""
lyr_def.featureTable.displayExpressionInfo = exp_info
lyr.setDefinition(lyr_def)
I really appreciate the help 🙂
Thanks for raising this question, and sharing your solution. I was working with this same issue and this has saved a lot of time.