I'm trying to use python to assign properties to a label class to a layer in my map in ArcGIS Pro 2.2.1, and no matter what I do, the changed properties do not appear when I examine the Label Class in the map. Below is an example of my code:
import arcpy
aprx = arcpy.mp.ArcGISProject(r"C:\Users\maxwell.reis\Desktop\USACE\Working_Map\Working_Map.aprx")
m = aprx.listMaps("Map")[0]
lyr = m.listLayers("TEMP_lyr")[0]
print(lyr.listLabelClasses("Class 1")[0].expression)
lblClass = lyr.listLabelClasses("Class 1")[0]
lblClass.expression = "$feature.PARNAME"
print(lyr.listLabelClasses("Class 1")[0].expression)
aprx.save()
The first print line correctly displays the label class expression of the layer in the map, and the second print line shows that the expression has successfully changed. However, when I go into the map to view the label class properties, nothing has changed.
Am I missing a step in the process? Is there another statement I need to make in python to get the map to recognize the updated Label Class Properties?
Solved! Go to Solution.
Just to confirm... ArcGIS Pro is not open when you are doing this and you open that project and check to see if the change was persisted to the map?
The opposite; I am doing this in the Python window within ArcGIS Pro.
Thank you, that did the trick!
Max, you might want to mark the correct answer so that other people know that a resolution was obtained.
@DanPatterson_Retired @DanPatterson ,
What do you make of this below? Thanks for all of your contributions!
'CURRENT' invalid when using Arcpy in Layer Labeli... - Esri Community
As a test can you try a Save As to a new aprx file name and see if the label class properties change there? Not an ideal solution if this works due to the structure of Pro where each aprx is tied to a file gdb so this solution could get messy.