def FindLabel ( [FIBER_ASSEMBLY_UNITS_ASSEMBLY_UNIT], [POLE_PRIKEY] ): if long( [POLE_PRIKEY] ) = long( [POLE_PRIKEY] ): return [FIBER_ASSEMBLY_UNITS_ASSEMBLY_UNIT] + '\n' + [FIBER_ASSEMBLY_UNITS_ASSEMBLY_UNIT] + '\n' + [FIBER_ASSEMBLY_UNITS_ASSEMBLY_UNIT] else: return [FIBER_ASSEMBLY_UNITS_ASSEMBLY_UNIT]
if long( [POLE_PRIKEY] ) = long( [POLE_PRIKEY] ):
def FindLabel([FIBER_ASSEMBLY_UNITS_ASSEMBLY_UNIT], [POLE_PRIKEY]): if long( [POLE_PRIKEY] ) == long( [POLE_PRIKEY] ): labelText = '{0}\n{1}\n{2}'.format([FIBER_ASSEMBLY_UNITS_ASSEMBLY_UNIT], [FIBER_ASSEMBLY_UNITS_ASSEMBLY_UNIT], [FIBER_ASSEMBLY_UNITS_ASSEMBLY_UNIT]) return labelText else: labelText = [FIBER_ASSEMBLY_UNITS_ASSEMBLY_UNIT] return labelText
There is no way I can think of to reference multiple rows as a single label using label expressions.
def FindLabel([QS], [TWP]): val_list = [] keyField = "TWP" keyVal = [TWP] field = "QS" fieldVal = [QS] layer = "ats" with arcpy.da.SearchCursor( layer, field, "{0} = {1}".format(keyField, keyVal)) as cursor: for row in cursor: val1 = row[0] val_list.append(val1) returnVal = "\n".join(val_list) return returnVal
I possibly found a way to do it. Not all that fast though. You'll have to change all the field names to your data. It will return a label for every feature populated by every item in your target field that match the key field value.
def FindLabel( [POLE_PRIKEY] , [FIBER_ASSEMBLY_UNITS_ASSEMBLY_UNIT] ): val_list = [] keyField = "POLE_PRIKEY" keyVal = [POLE_PRIKEY] field = "FIBER_ASSEMBLY_UNITS_ASSEMBLY_UNIT" fieldVal = [FIBER_ASSEMBLY_UNITS_ASSEMBLY_UNIT] layer = "TEST" with arcpy.da.SearchCursor( layer, field, "{0} = {1}".format(keyField, keyVal)) as cursor: for row in cursor: val1 = row[0] val_list.append(val1) returnVal = "\n".join(val_list) return returnVal
I know this is old, but I came across this link that helped me label from a related table with an advanced expression.
Tim,
I tried the code you linked to but it doesn't work for me. Any idea why?
Function FindLabel ( [UniqueID] )
Set gp = CreateObject("esriGeoprocessing.GPDispatch.1")
strWhereClause = chr(34) & "UniqueID" & chr(34) & " = '" & [UniqueID] & "'"
strpTable = C:\Users\abohn\Documents\RALLS_TEST.gdb\FIBER_ASSEMBLY_UNITS_AEG_gdb
Set prows = gp.searchcursor(strpTable,strWhereClause)
Set prow = prows.next
Do until prow is nothing
strLabel = prow.ASSEBMLY_UNIT
FindLabel = FindLabel & strLabel & vbnewline
Loop
End Function
The related table has to be added to the TOC. Make sure you are setting your strpTable variable to the actual table name (without the GDB path). I could not get it to work the way your are trying by using the full file path to the table. Also make sure the whereclause is querying on the correct foreign key (in your code it looks like your primary key and foreign key are named the same - which may be the case, just verify). Also make sure the "Advanced - VBscript" expression is used.
Sample code:
Function FindLabel ( [GlobalID] )
strWhereClause = "OperationGUID = '" & [GlobalID] & "'"
strpTable = "RelatedTableNameHere"
strLabel = prow.Description
Hope this helps!
Awesome! It works!! I can't believe it! So cool.
I didn't have quotes around my "PathToRelatedTable" so that works now and I don't have to have the table in my TOC then. But in production I actually want to use an SDE table so I will have that in my TOC so I will just use the "RelatedTableName" like you mentioned. Thank you!
I have a further question though. In my code below I added a Quantity field to my label. But when the Quantity is 1 I don't want it to put the "(1)" there. I just want the "(2)" quantity label when the Quantity > 1. Do you know how to add in this logic?
Code:
strpTable = "FIBER_ASSEMBLY_UNITS"
strLabel = prow.ASSEMBLY_UNIT & " (" & prow.Quantity & ")"
Thank you!
Přihlášení členové mohou přispívat, sledovat aktualizace a další. Jste tu noví? Zaregistrujte si bezplatný účet.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.