Label Expression Help

637
2
Jump to solution
05-28-2014 08:53 AM
ToddCalico
New Contributor
I'm trying to label electrical line features by the conductor type. I have three fields to work with one for each phase. Where more than one of these fields has a populated value (such as a three phase line), I only want to have one of them label. So I need some sort of expression that tells it to label only one field instead of all three in those instances.

Not a python or vb expert so any help would be appreciated.
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
Zeke
by
Regular Contributor III
Click the Expression button on the Label tab. Change the parser to Python and click Advanced. Delete any field names that may have automatically populated. Between the (), double click the three fields you want so that they're in the ()s, separated by commas. On the second line, indented, enter something like the code below, substituting your field names and in the order you'd prefer the label to be populated. This code checks for length to make sure a value exists, rather than None, because I don't know if your data has nulls or empty spaces. If fld1 has a value, that will be the label. If fld1 doesn't have a value, and fld2 does, fld2 will be the label, and so on.

You could do this in VBScript too, but I'm more familiar with python.

def FindLabel(fld1, fld2, fld3):     if len(fld1) > 0: return fld1     elif len(fld2) > 0: return fld2     elif len(fld3) > 0: return fld3     else: return

View solution in original post

0 Kudos
2 Replies
Zeke
by
Regular Contributor III
Click the Expression button on the Label tab. Change the parser to Python and click Advanced. Delete any field names that may have automatically populated. Between the (), double click the three fields you want so that they're in the ()s, separated by commas. On the second line, indented, enter something like the code below, substituting your field names and in the order you'd prefer the label to be populated. This code checks for length to make sure a value exists, rather than None, because I don't know if your data has nulls or empty spaces. If fld1 has a value, that will be the label. If fld1 doesn't have a value, and fld2 does, fld2 will be the label, and so on.

You could do this in VBScript too, but I'm more familiar with python.

def FindLabel(fld1, fld2, fld3):     if len(fld1) > 0: return fld1     elif len(fld2) > 0: return fld2     elif len(fld3) > 0: return fld3     else: return
0 Kudos
ToddCalico
New Contributor
Awesome Thank You!!!
0 Kudos