Solved

Return largest parameter value in scripted parameter (possible bug)

  • 1 April 2024
  • 2 replies
  • 31 views

Userlevel 3
Badge +26

 I have 3 published parameters where the user inputs values for buffers. All three were created as Numeric parameters, with numeric precision set to Integer. I would like to extract the largest buffer value in a python scripted parameter. This is the code I’m using in FME 2023 (build 23332)

buffer_list = [FME_MacroValues['BUFFER1'],FME_MacroValues['BUFFER2'],FME_MacroValues['BUFFER3']]
buffer_list.sort(reverse = True)

return buffer_list[0]

What I’ve discovered is that if the 3 buffers are the same number of digits, the script will return the correct value. If the number of digits is different, it will not. Some examples:

10, 40, 50 = 50 (correct)

120, 60, 70 = 70 (incorrect)

120, 180, 70 = 70 (incorrect)

120, 200, 300 = 300 (correct)

It doesn’t matter which order the values are input, nor does it matter how the parameters are sorted in the parameter list.

Is this a bug, or am I missing something?

icon

Best answer by debbiatsafe 2 April 2024, 02:53

View original

2 replies

Userlevel 3
Badge +18

Hello @dustin,

Parameter values are always fetched as strings. You will need to cast the parameter values to integers if you need to get the numerical max.

return max(int(FME_MacroValues['BUFFER1']),int(FME_MacroValues['BUFFER2']),int(FME_MacroValues['BUFFER3']))

Note the original behaviour noted is not a behaviour specific to FME. I believe strings are sorted based on code-point value of the first character.

Userlevel 3
Badge +26

Hello @dustin,

Parameter values are always fetched as strings. You will need to cast the parameter values to integers if you need to get the numerical max.

return max(int(FME_MacroValues['BUFFER1']),int(FME_MacroValues['BUFFER2']),int(FME_MacroValues['BUFFER3']))

Note the original behaviour noted is not a behaviour specific to FME. I believe strings are sorted based on code-point value of the first character.

This worked great, thank you.

Reply