I'm using Pro 3.2 currently. I'm trying to work on some code that runs a calculate field on a shapefile and then will label that shapefile once the calculation is done. I'm able to get this code working in Notebook running cell by cell, but once it put it into my actual code base, it's failing with this error message:
LayerObject: Label Class expression is not valid.
p = arcpy.mp.ArcGISProject('current')
m = p.listMaps('Map')[0]
l = m.listLayers()[0]
l.showLabels = True
lc1 = l.createLabelClass(
name = 'EI - VBScript2',
expression = '[MUSYM] & vbCrLf & Round([SLength], 0) & " ft." & " X " & Round([Avg_Slope], 0) & " ft." & vbCrLf & " EI = " & Round([EIFin], 2)',
sql_query = "",
labelclass_language = 'VBScript')
lc1.visible = True
When I'm looking at the shapefile after the failure message, all of my field calculations are being done correctly and being updated to the attribute table. It just seems to be having issues when it comes to displaying the label. I can also go through and manually label everything, but since this is going to be used by a few people, I'd rather just have the labels generate how they need to look.
I feel like I'm missing something super simple here to get it working. 😅