Comparing value of parameter to range of values brought in from Revit and selecting index corresponding to the range the parameter falls in

Hi, I was tasked with figuring out if auto-sizing storm piping with dynamo is something my office should adopt into our workflow. I created the graph below following an autodesk university class on pipe sizing but ran into an issue on the last step.

My goal is to pull the flow parameter from all storm piping (hydronic return classification) and compare this demand with the IPC storm piping sizing table that I have in excel (capacity) and then use that table to set the diameter parameter of the pipe. EX: a pipe with flow of 75 gpm falls in the range 56-115 and would require a 4" pipe. I originally used the list.firstindexof node to compare the demand and capacity lists but it returned all -1 values. I am guessing this is because the demand flow does not exactly match the capacity.

I messed with a couple other ideas but could not get anything to work

So, I just wrote a code block for the ranges and used Boolean filters. This got the job done but it is not very flexible. Ideally others in my office could use this in dynamo player and modify the capacities by editing the excel file and not have to edit the code block.

I am very new to dynamo so it is probably a simple fix but I have spent hours reading posts on here and cannot figure out what needs to be changed. Any suggestions would be greatly appreciated!

I think you are on the right track using an excel sheet instead of hard coding it in the Dynamo graph. Here is an example of how I would do it using only OOTB nodes:

With my excel looking like this:
excel%20pic

Alternatively the Python version would look like this:


Python code:

flows = IN[0]
excel = IN[1]

OUT = []
for flow in flows:
	for rmin, rmax, dia in excel:
		if flow >= rmin and flow < rmax:
			OUT.append(dia)

You can ignore everything past here but just for fun and because I forgot to respond to @Mark.Ackerley in a different post, here is where I would generally prefer a lambda function over nested for-loops within a single line:

Lambda:

flows = IN[0]
excel = IN[1]

f = lambda flow : [dia for rmin, rmax, dia in excel if flow >= rmin and flow < rmax][0]
OUT = map(f, flows)

vs Nested for-loop:

flows = IN[0]
excel = IN[1]

OUT = [[dia for rmin, rmax, dia in excel if flow >= rmin and flow < rmax][0] for flow in flows]

All of these python scripts work the same but for me, the fully laid out for loops and the lambda are the easiest to read. The last option just looks very complicated.

4 Likes

Thank you so much! It works perfectly.

1 Like

I’ve got something similar set up, but what I can’t seem to wrap my head around is this…

In a drainage system, pipe cannot reduce size in the direction of flow (code requirement). So, I’m trying to come up with a method that will check the sizes of all upstream pipes to make sure any particular pipe segment isn’t smaller than any segment upstream (or prior) to it.

Is there a way to pass a parameter through the piping system that tracks what the maximum upstream pipe size is it might there be some other recommendations to accomplish what I’m trying to do?

@tcook, did you account for this in your workflow?