I want to set the FindLabel function to the labelclass expression using ArcPy. My code is like How To: Label a related table. I don't want to load the function into the expression editor of the label tab but in the toolbox.
I try to load function programmatically but it's not working. What's wrong in the code?
Another problem is using brackets "" for field names. In the expression editor the users can write [field name] but in Python I must use string characters. Also FindLabel mainly uses an advanced expression in expression editor but I could not set the advanced expression and parser.
How can I use FindLabel Function programmatically?
import arcpy mxd = arcpy.mapping.MapDocument("CURRENT") layer = arcpy.mapping.ListLayers(mxd, "fc") def FindLabel ([keyField], [FirstLabel]): key1 = [keyField] # Key field in feature class key2 = "ID" # Key field in related table L = [FirstLabel] # Label field in feature class L2 = "Label2" # Label field in related table myDataTable = r"<path-to-related-table>" # Path to related table cur = arcpy.da.SearchCursor(myDataTable, [key2, L2]) for row in cur: if str(key1) == str(row): L = L + " " + str(row) return L layer.labelClasses.expression = .... ? print layer.labelClasses.expression layer.labelClasses.showClassLabels = True layer.showLabels = True arcpy.RefreshActiveView() del mxd