Pull highest value from two lists to create new list

Hello All!

Absolute Dynamo nube here, but I’m trying to bend my brain around this. I’m sure it’s easier than I’m making it, but I don’t know what I don’t know. :frowning:

I need to compare two lists (“Rough Width” and “Width”) and create a new list of values based on highest value from each, then use that new list to govern the “Width” of my newly placed family instance. The lists will always have the same number of responses, so my thought was to have a Python script compare line by line and return the greater value but I think I’m running into an issue with some of the values since they have an extensive decimal extension. Maybe? I dunno, I’m guessing…

The ultimate goal is to place a family instance in Revit at each door/window opening that matches the width of the overall opening. Since some families use a governing parameter of “Width” and some use “Rough Width”, I need to accommodate for both. My script works great for one or the other but not both. The value field for “Rough Width” is empty if it is not governing, which means I need the script to default to the “Width” value.

Here is a screen shot of what I currently have and the error I’m getting for my Python script:

Any help would be greatly appreciated!

Join the two lists into one with a List.Create node. Then use a List.Transpose node to get value pairs, and finally use a List.MaximumItem with level set to @L2 in order to get the larger of the two values.

1 Like

You can also use a simple conditional statement:
a > b ? a : b;

2 Likes

@Nick_Boyts , thank you! Um… where would I put the conditional statement?

You would provide the Rough Width and Width as the variables a and b and the result would be the higher value. You would then pass on that value to the instance as the new Width.

A null value might cause some issues with this, but worth a shot as it would be one node.

True, I missed that part. You would either need to ensure you have no nulls (replace with 0) or include another condition for null or empty values.

I fear the Null is causing issues:

I’ll give it a whirl…

hello


cordially
christian.stan

This is closer! However, I need for it to do a line by line comparison of which value is greater.

For what it’s worth, I’ve tried approaching this with a couple of different angles, but the list comparison seemed to be the cleanest.

You changed the list structure with AllIndicesOf (it returns a list).

You can use something like ReplaceByCondition (which would require you to address both null and empty conditions separately) or use another nested conditional statement for values equal to null or empty ("").

1 Like


cordially
christian.stan

So, I tried flattening the list and that seemed to work:

Unless I’m missing something?

Thank you! I tried it and it still seemed to return only the highest values, not the highest value per line, but I will store the information that I can specify the level like that.

1 Like

That does work but you’re better off just not adding the extra level to begin with. Instead, convert your non-numeric values to 0 with a conditional statement.

4 Likes

That’s the bit of code that I kept circling around but didn’t know enough to put it together on my own. Thank you!!