3

I am trying to do some conditional formatting in order to highlight specific criteria. The main error I keep getting is that there are no features found. I've done a simple label with the exact same parameters that works fine. I've also occasionally gotten an error that says the function FindLabel is not defined. Thinking now, I might need a nested if statement. I have 4 parameters, [Percentage_Complete], that if they exceed the criteria of 90, then I want to change the color to green. If it doesn't it will stay black. So 1 to 4 of them could be green, or they are all black text.

Basic Label Expression

def FindLabel ([SWSID], [Stn_Name], [First_Date_In_DB], [Last_Date_In_DB], [Percentage_Complete], [First_Date_In_DB1], [Last_Date_In_DB_1], [Percentage_Complete1], [First_Date_In_DB2], [Last_Date_In_DB_2], [Percentage_Complete2], [First_Date_In_DB3], [Last_Date_In_DB_3], [Percentage_Complete3]):

lab1 = "T_avg" + "  " + [First_Date_In_DB]+ "  " + [Last_Date_In_DB] + "  " + [Percentage_Complete]+"\n"
lab2 = "Snowfall"+ "  " + [First_Date_In_DB1]+ "  " + [Last_Date_In_DB1] + "  " + [Percentage_Complete1]+"\n"
lab3 = "Snow Depth"+ "  " + [First_Date_In_DB2]+ "  " + [Last_Date_In_DB2] + "  " + [Percentage_Complete2]+"\n"
lab4 = "Rain"+ "  " + [First_Date_In_DB3]+ "  " + [Last_Date_In_DB3] + "  " + [Percentage_Complete3]"\n"
higlight =  "<bol><clr green='255'>"
endhigh = "</bol></clr><\n>"


if int([Percentage_Complete]) >= 90:
lab1 =  highlight + lab1 + endhigh
if int([Percentage_Complete1]) >= 90:
lab2 =  highlight + lab2 + endhigh
if int([Percentage_Complete2]) >= 90:
lab3 =  highlight + lab3 + endhigh
if int([Percentage_Complete3]) >= 90:
lab4 =  highlight + lab4 + endhigh

label = "<und><bol>"+[SWSID]+"</bol></und>"+ "    "+ "<und><bol>"+[Stn_Name]+"</bol></und>\n" + lab1 + lab2 + lab3 + lab4

return label

  • 1
    The final else condition is never realized, since label gets overwritten after the conditional block. I think you need to define defaults for lab1, lab2, etc. inside that else block instead. (I don't know if that is the only problem, but it's what jumped out at me.) – Erica Jul 21 '14 at 14:20
  • The indentation under else for label looks off to me, as well as no ending quotations. As well you might want to change lab1, lab2, etc with just FindLabel = – GISKid Jul 21 '14 at 14:24
  • And this is why I think I need the nested if, because if all four meet the condition I need them all to be green. I added what I can get from the simple expression to the original post, I just want to be able to color the different lines to make them stand out if they exceed that 90 criteria. – twistr25 Jul 21 '14 at 14:29
  • You could always try using sql queries instead. Might be a bit easier! Or alternatively, try if int ([Percentage_Complete], [Percentage_Complete2] >=90; not sure if that is valid, or if you can use or statements. – GISKid Jul 21 '14 at 14:38
3

I think you might be somewhat along the right lines, but, what about something more along the lines of:

lab1 = line's value
lab2 = line's value
...

if line 1 condition >= 90
    lab1 = bold and green + lab1 + end bold and green
if line 2 condition >= 90
    lab2 = bold and green + lab2 + end bold and green
...

label = bold and underline + header line text + end bold and underline + \n + lab1 + \n + lab2 ...

Hope that gives you some ideas.

  • +1, I think this will greatly improve the code's readability and usability. – Erica Jul 21 '14 at 15:07
  • 2
    They could also set the bold and green as vars. Such as highlight = "<bol><clr green='255'>", and if condition1 >= 90 then label1 = highlight + values + endtags, else label1 = nohighlight + values + endtags (define highlight, nohighlight, endtags as appropriate) – KiloGeo Jul 21 '14 at 15:21
  • Ok, I changed the code and I think everything looks good now and should work, but I'm still getting the no features found error with the exact same parameter array I use for the simple expression.... – twistr25 Jul 21 '14 at 16:16
  • @twistr25 is the parser on your label expression set to Python? – John Jul 21 '14 at 16:36
  • It is. I found that if I hand clicked in each of the parameters it seemed to like that, didn't like me to add them in the expression first. Now for the font formatting tags it is turning the highlight = "<bol><clr green='255'>" into text and if I remove the quotes it gives me a syntax error. In the simple expression it works fine though – twistr25 Jul 21 '14 at 17:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.