1

Is there an ArcPy method for amending the heading of a layer's symbology without having to amend the field name (which would be problematic)?

I know how to change the layer's name & the classificationField that the symbology refers to, but I cannot find any documentation on amending the field name in the TOC so that something more meaningful appears in the legend.

3
  • 1
    If the UI permits it, then this is a function of ArcObjects, but not all AO capabilities were ported to Python, so it's possible that you cannot do this directly in Python.
    – Vince
    Commented Dec 21, 2021 at 16:54
  • 1
    Take a look at the CIM document: pro.arcgis.com/en/pro-app/latest/arcpy/mapping/…
    – KHibma
    Commented Dec 21, 2021 at 16:56
  • I've voted to re-open this. I'm not sure how we expect someone to provide a code sample when they're asking "is it even possible to do a code solution" >> They don't know if a method exists. Hard to write code around that.
    – KHibma
    Commented Dec 22, 2021 at 13:00

2 Answers 2

3

From the CIM (Cartographic Information Model), I think the piece you want to modify can be found/updated with the following code

p = arcpy.mp.ArcGISProject('CURRENT')
m = p.listMaps('MapName')[0]
l = m.listLayers('LayerName')[0]
cim = l.getDefinition('V2')
cim.renderer.groups[0].heading = "Symbolized by : {}".format(cim.renderer.fields[0])
l.setDefinition(cim)

You'll need to determine what exactly you want to put into the heading. You mentioned the field name -- I grabbed the field name from the first item in the fields list.

0
   p = arcpy.mp.ArcGISProject('CURRENT')
   m = p.listMaps('MapName')[0]
   l = m.listLayers('LayerName')[0]
   cim = l.getDefinition('V3')
   cim.colorizer.heading = "My new heading"   
   l.setDefinition(cim)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.