Select to view content in your preferred language

Default Language for Label Class

547
2
11-22-2023 01:19 AM
SumanGeo
New Contributor

I want to apply labeling in multiple layers using Arcade Expression in ArcGIS Pro, So I created below python script, and I also set Arcade to apply labeling: label_class.expression = "Arcade".

But problem is- Arcade language changes to VBScript or other language other than Arcade after running the script. I have to set manually Arcade each time for each layer, then apply the script, and then work. What is the solution to set default Language Arcade that will not change after running the script?

import arcpy

def set_labels():

    aprx = arcpy.mp.ArcGISProject("CURRENT")
    m = aprx.listMaps()[0]

    layer_types = ["PD", "LD"]
    name_field_mapping = {
        "PD": ["P_Desc", "Label_En", "Label_Bn"],
        "LD": ["L_Desc"],
    }

    for lyr in m.listLayers():
        for layer_type in layer_types:
            if layer_type in lyr.name:

                if lyr.supports("SHOWLABELS"):
                    if not lyr.listLabelClasses():
                        label_class = lyr.labelClasses[0]
                    else:
                        label_class = lyr.listLabelClasses()[0]

                    # Setting label expression language to Arcade
                    label_class.expression = "Arcade"
                    if layer_type == "PD":
                        label_expression = """ "<BSE>"+"<ALIGN horizontal = 'middle'>"+"<FNT name = 'Work Sans' style = 'italic' named_instance = 'bold italic' wght = '700' size = '13'>" + "<CLR blue = '255'>" + $feature.P_Desc + "</CLR>" +TextFormatting.NewLine+"<BOL>" + "<CLR red='255' green='236' blue='0' alpha='100'>"+"<BGD red='0' green='0' blue='0' alpha='100'>" +"<_ITA>"+ $feature.Label_En + "</_ITA>"+"</BGD></CLR>" + "</BOL>" + TextFormatting.NewLine + "<CLR red='255' green='255' blue='255' alpha='100'>"+"<BGD red='230' green='0' blue='0' alpha='100'>" + $feature.Label_Bn + "</BGD></CLR>" + "</FNT>"+"</ALIGN>"+"</BSE>" """

                    elif layer_type == "LD":
                        label_expression = """ "<BSE>"+"<ALIGN horizontal = 'middle'>" + "<FNT name = 'Work Sans' style = 'italic' named_instance = 'bold italic' wght = '700' size = '13'>" + "<CLR red = '255'>" + $feature.L_Desc + "</CLR>" + "</FNT>" + "</ALIGN>"+ "</BSE>" """
                        label_class.SQLQuery = "L_Desc <> 'Plot'"
                    else:
                        label_expression = f"${name_field_mapping[layer_type][0]}"

                    label_class.expression = label_expression

                    label_class.showClassLabels = True

                    lyr.showLabels = True

    aprx.save()

set_labels()

 

2 Replies
VeraNeroni1
Occasional Contributor

I have also run into this issue - commenting to see if anyone has come up with a solution.

0 Kudos
JesseWickizer
Esri Contributor

In line 25 you set label_class.expression to "Arcade". Set the expressionEngine property instead:

label_class.expressionEngine = 'Arcade'

 

0 Kudos