Hello All,
I am having trouble trying to convert VBScript label expressions to Python. I've tried running them through AI to help convert, but no luck. Is there a way within the ArcGIS Pro software to complete this?
Thanks!
Solved! Go to Solution.
Untested but try something like this,
python phrase,
def LabelBlockLineFormatter(Descripter, Value):
if Descripter == "Above Criteria":
return f"<CLR red='255'>{Value}</CLR>"
elif Value == 0:
return "ND"
elif Value is None or Value == "<Null>":
return "NS"
else:
return str(Value)
def FindLabel(F1, Total_VOC_Jun_2017, Total_VOC_Notes_Jun_2017,
Total_VOC_Oct_2017, Total_VOC_Notes_Oct_2017,
Total_VOCs_2019_08, Total_VOCs_Notes_2019_08,
Total_VOC_April_2022, Total_VOC_Notes_April_2022):
label = f"<BOL><UND>{F1}</UND></BOL>"
label += "\n" + LabelBlockLineFormatter(Total_VOC_Notes_Jun_2017, Total_VOC_Jun_2017)
label += "\n" + LabelBlockLineFormatter(Total_VOC_Notes_Oct_2017, Total_VOC_Oct_2017)
label += "\n" + LabelBlockLineFormatter(Total_VOCs_Notes_2019_08, Total_VOCs_2019_08)
label += "\n" + LabelBlockLineFormatter(Total_VOC_Notes_April_2022, Total_VOC_April_2022)
return label
expression line
FindLabel(!F1!, !Total_VOC_Jun_2017!, !Total_VOC_Notes_Jun_2017!,
!Total_VOC_Oct_2017!, !Total_VOC_Notes_Oct_2017!,
!Total_VOCs_2019_08!, !Total_VOCs_Notes_2019_08!,
!Total_VOC_April_2022!, !Total_VOC_Notes_April_2022!)
It would help if you posted what you are trying to convert.
I was just curious if there was a method within ArcGIS Pro to automatically convert it. But here is the VBS code I'm working with.
Function FindLabel ( [F1], [Total_VOC_Jun_2017], [Total_VOC_Notes_Jun_2017], [Total_VOC_Oct_2017], [Total_VOC_Notes_Oct_2017], [Total_VOCs_2019_08], [Total_VOCs_Notes_2019_08], [Total_VOC_April_2022], [Total_VOC_Notes_April_2022])
FindLabel="<BOL><UND>" & [F1] & "</UND></BOL>"
FindLabel = FindLabel & vbNewLine & LabelBlockLineFormatter([Total_VOC_Notes_Jun_2017], [Total_VOC_Jun_2017])
FindLabel = FindLabel & vbNewLine & LabelBlockLineFormatter([Total_VOC_Notes_Oct_2017], [Total_VOC_Oct_2017])
FindLabel = FindLabel & vbNewLine & LabelBlockLineFormatter([Total_VOCs_Notes_2019_08], [Total_VOCs_2019_08])
FindLabel = FindLabel & vbNewLine & LabelBlockLineFormatter([Total_VOC_Notes_April_2022], [Total_VOC_April_2022])
End Function
Function LabelBlockLineFormatter([Descripter], [Value])
if([Descripter] = "Above Criteria") then
LabelBlockLineFormatter = "<CLR red = '255'>" & [Value] & "</CLR>"
elseif ([Value] = 0) then
LabelBlockLineFormatter = "ND"
elseif isnull([Value]) then
LabelBlockLineFormatter = "NS"
else
LabelBlockLineFormatter = [Value]
end if
End Function
Untested but try something like this,
python phrase,
def LabelBlockLineFormatter(Descripter, Value):
if Descripter == "Above Criteria":
return f"<CLR red='255'>{Value}</CLR>"
elif Value == 0:
return "ND"
elif Value is None or Value == "<Null>":
return "NS"
else:
return str(Value)
def FindLabel(F1, Total_VOC_Jun_2017, Total_VOC_Notes_Jun_2017,
Total_VOC_Oct_2017, Total_VOC_Notes_Oct_2017,
Total_VOCs_2019_08, Total_VOCs_Notes_2019_08,
Total_VOC_April_2022, Total_VOC_Notes_April_2022):
label = f"<BOL><UND>{F1}</UND></BOL>"
label += "\n" + LabelBlockLineFormatter(Total_VOC_Notes_Jun_2017, Total_VOC_Jun_2017)
label += "\n" + LabelBlockLineFormatter(Total_VOC_Notes_Oct_2017, Total_VOC_Oct_2017)
label += "\n" + LabelBlockLineFormatter(Total_VOCs_Notes_2019_08, Total_VOCs_2019_08)
label += "\n" + LabelBlockLineFormatter(Total_VOC_Notes_April_2022, Total_VOC_April_2022)
return label
expression line
FindLabel(!F1!, !Total_VOC_Jun_2017!, !Total_VOC_Notes_Jun_2017!,
!Total_VOC_Oct_2017!, !Total_VOC_Notes_Oct_2017!,
!Total_VOCs_2019_08!, !Total_VOCs_Notes_2019_08!,
!Total_VOC_April_2022!, !Total_VOC_Notes_April_2022!)
Had to do some minor tweaks but this worked! Thank you so much!
Right on! Happy to help!
Best way is to just manually port them over, but we can't help without the original script as Tony said