Select to view content in your preferred language

Strange Python vs Arcade symbology issue

584
3
05-19-2023 03:18 PM
nsidaniel
New Contributor III

For the TWP+"_Sections" layer I have to set the lblClass.expression with python, for the TWP+"_QRT_sections" layer I have to set it with Arcade, otherwise neither layer works! It's the strangest thing. The problem repeats with each new dataset.

Here's the code in question:

for m in aprx.listMaps("Map"):

    for lyr in m.listLayers(TWP+"_Sections"):
        sym = lyr.symbology
        lblClass = lyr.listLabelClasses()[0]
        print("Layer name: " + lyr.name)
        lblClass.expression = "\"<FNT name= 'Arial' size= '14' style= 'bold'>\" + \"<CLR red= '0' green= '38' blue= '138'>\" + [FRSTDIVNO] + \"</CLR>\" + \"</FNT>\""
        #lblClass.expression = "\"<FNT name= 'Arial' size= '14' style= 'bold'>\" + \"<CLR red= '0' green= '38' blue= '138'>\" + $feature.FRSTDIVNO + \"</CLR>\" + \"</FNT>\""
        lyr.showLabels = True
        sym.renderer.symbol.color = {'RGB' : [0, 0, 0, 0]}
        sym.renderer.symbol.outlineColor = {'RGB' : [0, 38, 138, 100]}
        sym.renderer.symbol.outlineWidth = 4
        lyr.symbology = sym
        p.saveACopy(os.path.join("CURRENT"))


    for lyr in m.listLayers(TWP+"_QRT_sections"):
        sym = lyr.symbology
        lblClass = lyr.listLabelClasses()[0]
        print("Layer name: " + lyr.name)
        #lblClass.expression = "\"<FNT name= 'Arial' size ='10' style= 'bold'>\" + \"<CLR red= '137' green= '137' blue= '68'>\" + [SECDIVNO] + \"</CLR>\" + \"</FNT>\""
        lblClass.expression = "\"<FNT name= 'Arial' size ='10' style= 'bold'>\" + \"<CLR red= '137' green= '137' blue= '68'>\" + $feature.SECDIVNO + \"</CLR>\" + \"</FNT>\""
        lyr.showLabels = True
        sym.renderer.symbol.color = {'RGB' : [0, 0, 0, 0]}
        sym.renderer.symbol.outlineColor = {'RGB' : [171, 205, 102, 100]}
        sym.renderer.symbol.outlineWidth = 4
        lyr.symbology = sym
        p.saveACopy(os.path.join("CURRENT"))  

 

Any ideas?

0 Kudos
3 Replies
RhettZufelt
MVP Notable Contributor

Any chance the label class(es) for TWP+"_QRT_sections" in the map are set to arcade language and the other to Python?

 

RhettZufelt_0-1684539211745.png

 

R_

JohannesLindner
MVP Frequent Contributor

That's probably it. To set the expression engine, you have to use the CIM:

    for lyr in m.listLayers(TWP+"_Sections"):
        cim = lyr.getDefinition("V3")
        for lblClass in cim.labelClasses:
            lblClass.expressionEngine = "Arcade"
        lyr.setDefinition(cim)
        # rest of the code

 


Have a great day!
Johannes
nsidaniel
New Contributor III

Thank you @RhettZufelt and @JohannesLindner . It's always something simple!

0 Kudos