Hello everyone,
I am trying to write code that saves label expressions before performing an Add Join, as the join process messes up the expressions. After the Add Join is completed, I plan to restore the label expressions.
We are on the verge of migrating from the arcpy.mapping module to the arcpy.mp module. According to the documentation, it seems that label functionality has been changed to the LabelClass object. I can confirm that my layer supports label expressions, as shown by the command lyr.supports("SHOWLABELS"). However, when the code reaches the part where a setDefinition is implemented, I get an error message.
"ArcGIS Pro caused an error and it causes script to break".
code used in arcpy.mapping (just of reference):
lblExpression = opplan_outline.labelClasses[0].expression
performing Add join
# retrieving label expression
opplan_outline.labelClasses[0].expression = lblExpression
Code I am trying to convert in arcpy.mp module
opplan_outline = map_obj.listLayers("Opplan_Layer_Outline")[0]
label_defs = []
if opplan_outline.supports("SHOWLABELS"):
for lblClass in opplan_outline.listLabelClasses():
label_defs.append(lblClass.getDefinition("V3"))
performing add join
if opplan_outline.supports("SHOWLABELS"):
for i, lblClass in enumerate(opplan_outline.listLabelClasses()):
lblClass.setDefinition(label_defs[i])
Error message is ArcGIS Application has stopped working. even though Arcgis Pro is not open. And I have also figured out that the issue lies in when the set definition comes into place.

Thank you everyone in advance.