Skip to main content
Solved

Return largest parameter value in scripted parameter (possible bug)


dustin
Influencer
Forum|alt.badge.img+31

 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?

Best answer by debbiatsafe

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.

View original
Did this help you find an answer to your question?

2 replies

debbiatsafe
Safer
Forum|alt.badge.img+20
  • Safer
  • Best Answer
  • April 2, 2024

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.


dustin
Influencer
Forum|alt.badge.img+31
  • Author
  • Influencer
  • April 2, 2024
debbiatsafe wrote:

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.


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings