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
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.
Hope that helps.
This might be a useful thread