Skip to main content
Solved

Return largest parameter value in scripted parameter (possible bug)

  • April 1, 2024
  • 2 replies
  • 52 views

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.

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

2 replies

debbiatsafe
Safer
Forum|alt.badge.img+21
  • 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

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.