Is it possible to access to the range labels set within Layer Properties > Symbology tab? (see image)screengrab of layer properties

I have numerous layers with different class ranges and would like to export range values as plain text to use elsewhere, rather than ctrl-c ctrl-v for each class in each layer.


Following the pointer from @Vince I've tried the following ArcPy script built through advice at http://desktop.arcgis.com/en/arcmap/10.3/analyze/arcpy-mapping/labelclass-class.htm

import arcpy

mxd = arcpy.mapping.MapDocument(r"path\to\my_mxd.mxd")

for lyr in arcpy.mapping.ListLayers(mxd):
    if lyr.supports("LABELCLASSES"):
        for lblClass in lyr.labelClasses:
            print "Layer name: " + lyr.name
            print "    Expression:  " + lblClass.expression

del mxd

But lblClass.expression doesn't access the labels needed. Is there another property I can access? Can't see a suitable one in ArcPy classes LabelClass or Layer.

  • 1
    You'll need to write a dozen lines of Python using arcpy.mapping, but yes, it's possible. – Vince Aug 30 '17 at 10:11

Not a complete answer, but a hint to the code above: It has nothing to do with labes (in terms of "labeling of a layer"), i fear, but with the layers symbology and the list property classBreakLabels as lyr.symbology.classBreakLabels.

mxd = arcpy.mapping.MapDocument("CURRENT")
for lyr in arcpy.mapping.ListLayers(mxd):
        for clbrkLabel in lyr.symbology.classBreakLabels:
            print clbrkLabel
    except NameError as e:
        print lyr.name, e
    except AttributeError as e:
        print lyr.name, e

prints out the TOC's labels, if symbology supports this...

  • Accepting this answer. Layer symbology is where to go. – mark Aug 30 '17 at 14:47
  • In this sample, to change the labels use = where now printing, e.g. lyr.symbology.classBreakLabels = ["Label 1", Label 2", ...]. This changes all labels at once and needs to exactly match the list length of the classes breaks. – matt wilkie Oct 25 '17 at 21:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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