Select to view content in your preferred language

Python and ArcGIS Pro 2.2

443
1
03-06-2023 12:54 PM
GeorgeJones9282
Emerging Contributor

Hi all, i'm trying to set a label constraint to only label only those features that are not assigned to 999. So far my code doesn't work but I've tried the following below:

import arcpy
aprx = arcpy.mp.ArcGISProject("CURRENT")
qry = "facilityNumber <> '999'"
for map in aprx.listMaps():
     for lyr in map.listLayers():
         if lyr.supports("SHOWLABELS"):
             if lyr.showLabels == qry:
            print("Layer name: " + lyr.name)
           for lblClass in lyr.listLabelClasses():
                 print("\t Class Name: \t" + lblClass.name)
                 print("\t Expression: \t" + lblClass.expression)
                print("\t SQL Query: \t" + lblClass.SQLQuery)
del aprx

 

 

Tags (2)
0 Kudos
1 Reply
LyonMNGIS
Frequent Contributor

George,

I don't have the answer for you offhand, but I did notice a couple items that you may want to consider.

First, make sure that facilityNumber is a text value and not a numerical value.  Searching for 999 as an integer is not the same as searching for '999' as a text value.

Second,  lyr.showLabels is a true or false value which toggles  labels on or off for a given layer.  It is not the underlying definition query.

Check out  https://community.esri.com/t5/python-questions/labels-still-not-visible-after-setting-lyr/m-p/378362...

Hope that helps.

 

 

 

This might be a useful thread

0 Kudos