Different Outcome with same Inputs - Python Script

Hi everyone,

I am currently trying to find the next level from a list of level elevations below a specific different elevation. The python script I wrote works fine if I put in a double from a code block. But the elevation I actually want to put in (coming from an element) does not show the desired outcome.

I couldn’t really name the problem, therefore I was not able to find anything similar in the forum, but maybe you guys can help? What did I do wrong?

Greets,
Lukas

I would do something as follows depending on which direction you want.

Its easyer if you sort your level list by the elevation:

you can also use “list.SortListByAnother” from the archilab package if you don’t have orchid.
image

Thanks you guys for the quick help. Both workarounds work fine, although I prefer the approach by @Fiesta.

I still wanted to find out what causes the problem I had and dug deeper. I found out that if you convert the double into a string by python, the number is somehow not 0.105 as expected, but 0.10499999999995. This way, it found the wrong level elevation. So I just added 0.00001 to the element elevation and everything works just fine.

Never assume you need to add to the number to make it a 3 digit number.

Anyway i would suggest you to do either of these options within the image that fits what is best for you.

1 Like