Get height if retaining wall using python

I have distances between two list of points and then I want to compare them to a list if prefabricated retaining walls using python.

IN[0] is the investigated difference in elevations
IN[1] is the amount of numbers of points.

I actually don’t understand how to use python in dynamo, it always returns error.

import sys
import clr

h = IN[0]
st = IN[1]

for i in range (0 , st+1):
if 0 < h < 0.4:
h = 0.4
elif 0.4 < h < 0.6:
h = 0.6
elif 0.6 <h < 0.8:
h=0.8
elif 0.8 < h < 1.0:
h=1.0
elif 1.0 < h < 1.2:
h=1.2
elif 1.2 < h < 1.4:
h=1.4
elif 1.4 < h < 1.6:
h = 1.6
elif 1.6 < h < 1.8:
h = 1.8
else:
h = 2.0

OUT = out

Your heights list is a list of lists, so you whenever you refer to ‘h’ you are referring to that (not the items in it). If you could work with a flat list, you could instead just iterate through it instead of st+1 range.

You’re also declaring OUT as a variable called ‘out’, but not using it or declaring it earlier in your code. Most workflows will append values to an empty list declared early in the code, then send that to OUT.

Here’s an example of you could find the value above to nearest 0.2 interval, iterating through a flat list of values:

# You need the math package
import math

# Your input of heights
IN[0] = [0.1,0.2,0.4,0.55,0.82,0.93]

# An optional interval
interval = 0.2

# We need a list to append results to
heightsOut = []

# For each height...
for h in heights:
    # How many intervals of 0.2 rounded up
    c = math.ceil(h/interval)
    # Append it * interval, round to 1dp
    heightsOut.append(round(c * interval, 1))

# Send the output to Dynamo
OUT = heightsOut

3 Likes

Hello
connect your IN[0] to your output after list.Flatten
then replace your your line
for i in h:

edit:
if you leave your for loop as is and the same connections, you must replace h by h[0][0][i]

edit2:
evening tiredness, it’s time to go to bed sorry:


import sys

h=IN[0]
out=[]

for i in h:
    if 0 < i <= 0.4:
        out.append(0.4)
    elif 0.4 < i <= 0.6:
        out.append(0.6)
    elif 0.6 < i <= 0.8:
        out.append(0.8)
    elif 0.8 < i <= 1.0:
        out.append(1.0)
    elif 1.0 < i <= 1.2:
        out.append(1.2)
    elif 1.2 < i <= 1.4:
        out.append(1.4)
    elif 1.4 < i <= 1.6:
        out.append(1.6)
    elif 1.6 < i <= 1.8:
        out.append(1.8)
    else:
        out.append(2.0)

OUT = out

Mr. Gavin’s code is more optimized

sincerely
christian.stan

1 Like

Thanks a lot for your effort.
With your help the graph works fine❤️

2 Likes