For a layer object lyr, one can programmatically set the minScale in arcpy as such:

lyr.minScale = 150000

For a label, one can manually set the scale range within a dialog in ArcMap. In arcpy, is there a way to programmatically set the minScale for a layer's label in much the same way one can for the layer itself?

I see that it can be done through the JavaScript API, but I haven't yet found a way via arcpy. (I have ArcMap 10.1 SP1.)


I looked at the LabelClass (arcpy.mapping) properties, which is where I believe this would need to be exposed and there is no such property available there either.

Consequently, for this one I suspect your best option will be to submit an ArcGIS Idea.

There is a generic idea to Expose the ArcMap layer properties through ArcPy which may lead to it being added.

However, I think we will see this functionality sooner if a specific one is submitted. If you do that post a link to it into your Question so that future visitors can also vote for it.

| improve this answer | |

Here's an example of using ArcObjects in Python to get at this information. I leave modifying the values and saving the MXD as an exercise to the reader:

import arcpy
from ESRICOMHelpers import *
esriSystem = GetESRIModule("esriSystem")
esriCarto = GetESRIModule("esriCarto")

def enumerate_feature_layers(map):
    uid = NewObj(esriSystem.UID, esriSystem.IUID)
    uid.value = "{E156D7E5-22AF-11D3-9F99-00C04F6BC78E}" # IGeoFeatureLayer
    enumLayer = map.Layers(uid, True)
    layer = enumLayer.Next()
    while layer:
        yield layer
        layer = enumLayer.Next()

def enumerate_label_classes(layer):
    labelClasses = CType(layer, esriCarto.IGeoFeatureLayer).AnnotationProperties
    for i in range(labelClasses.Count):
        labelClass, labelClassId = CType(labelClasses, esriCarto.IAnnotateLayerPropertiesCollection2).QueryItem(i)
        yield labelClass

def open_map_document(path):
    mxd = NewObj(esriCarto.MapDocument, esriCarto.IMapDocument)
    return mxd

def print_label_classes(mxd_path):
    mxd = open_map_document(mxd_path)
    map = mxd.Map[0]
    layers = enumerate_feature_layers(map)
    for layer in layers:
        print layer.Name
        for labelClass in enumerate_label_classes(layer):
            print "\tname: {0}, minScale: {1}, maxScale: {2}".format(labelClass.Class, labelClass.AnnotationMinimumScale, labelClass.AnnotationMaximumScale)

if __name__ == '__main__':
    mxd_path = r"path\to\map.mxd"

Get comtypes here.

The ESRICOMHelpers module is here.

Also note that for 10.1 and up you need to fix automation.py in the comtypes site package.

| improve this answer | |
  • I was hoping to avoid ArcObjects, but if it's not available natively, I guess that's that! I have other tools in this project using it via comtypes, so I won't have too much more work to do. Thanks! – Edwin S. Apr 9 '14 at 13:02

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.