HOW TO
In ArcGIS Pro, related tables of any geodatabase table or feature class can be labeled based on fields using tools from the Fields toolset. This article provides the workflow to label related tables with tools from the Fields toolset by running an ArcPy script in ArcGIS Pro.
def FindLabel (<keyField1>, <firstLabel>): import arcpy key1 = <keyField1> # The key field in the feature class key2 = "<keyField2>" # The key field in the related table L = <firstLabel> # The label field in the feature class L2 = "<label2>" # The label field in the related table myDataTable = r"<path-to-related-table>" # The related table file path cur = arcpy.da.SearchCursor(myDataTable, [key2, L2]) for row in cur: if str(key1) == str(row[0]): L = L + " " + str(row[1]) return L
The following code block demonstrates the full working script.
def FindLabel ([ENAME], [CNAME]): import arcpy key1 = [ENAME] # Key field in feature class key2 = "District" # Key field in related table L = [CNAME] # Label field in feature class L2 = "Population" # Label field in related table myDataTable = r"C:\Users\IDT27\Documents\Artwrk\29840\HKPOP\HKPOP.gdb\HK2016_Census_csv" # Path to related table cur = arcpy.da.SearchCursor(myDataTable, [key2, L2]) for row in cur: if str(key1) == str(row[0]): L = L + " " + str(row[1]) return L
Get help from ArcGIS experts
Download the Esri Support App