Why won't Label Class properties appear in Map after python modification?

212
6
Jump to solution
09-26-2018 06:43 AM
MaxReis
New Contributor II

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?

0 Kudos
1 Solution

Accepted Solutions
DanPatterson_Retired
MVP Esteemed Contributor

then you want "Current" aprx 

Guidelines for arcpy.mp—ArcPy | ArcGIS Desktop 

not the one on disk

View solution in original post

6 Replies
DanPatterson_Retired
MVP Esteemed Contributor

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?

MaxReis
New Contributor II

The opposite; I am doing this in the Python window within ArcGIS Pro.

0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor

then you want "Current" aprx 

Guidelines for arcpy.mp—ArcPy | ArcGIS Desktop 

not the one on disk

View solution in original post

MaxReis
New Contributor II

Thank you, that did the trick!

0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor

Max, you might want to mark the correct answer so that other people know that a resolution was obtained.

MichaelVolz
Esteemed Contributor

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.

0 Kudos