Labeling a Bunch of Layers with Arcpy

369
1
Jump to solution
05-25-2022 11:52 AM
JorgeKappa
Occasional Contributor

It prints the classes' names, and then it blows up with the error below.

Can somebody clue me in, please?

TIA

p = arcpy.mp.ArcGISProject("CURRENT")
m = p.activeMap
for lyr in m.listLayers("*"):
lblClass = lyr.listLabelClasses()[0]
print(lblClass.name)
lblClass.expression = "$feature.Text"
lyr.showLabels = True

Traceback (most recent call last):
File "<string>", line 4, in <module>
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\_mp.py", line 529, in listLabelClasses
return convertArcObjectToPythonObject(self._arc_object.listLabelClasses(*gp_fixargs((wildcard,), True)))
RuntimeError

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
JorgeKappa
Occasional Contributor

Never mind. It worked, but it threw the error because I had CAD layers in the TOC.

View solution in original post

0 Kudos
1 Reply
JorgeKappa
Occasional Contributor

Never mind. It worked, but it threw the error because I had CAD layers in the TOC.

0 Kudos