Running if statement logic within list loop still runs the true action even when false

I don’t have a coding background, so appreciate the patience with this question if it’s really obvious - I wasn’t able to find anything on the forum but maybe it’s there and I didn’t understand it.

I have a list of intersection from geometries derived from views and a surface derived from a view so I can find the biggest area of intersection (goal, find “the” room the view is intended to describe from all the rooms the view can see). Unfortunately, sometimes this intersection will result in a non-surface geometry, so there is no “area” to take. My solution was to set-up an if statement by object type so that the Surface.Area would only run on a true return that the list item is a Surface object and return a 0 otherwise. (top set of nodes not in a group in the below graph)

While the If loop works for the result, the Surface.Area still runs on the entire list and returns an error on the items that aren’t surfaces. So I tried using DesignScript to nest the if statement into the list action so it wouldn’t run the area on inputs that aren’t surfaces, but it still generates the same outcome (nodes inside the group in the graph). See below DesignScript:

a; (list with inputs to take area of)
b; (list input object types to filter non-areas)
out = List.Equals(b@@L1<1>, “Autodesk.DesignScript.Geometry.Surface”)? Autodesk.Surface.Area(a@@L1<1>):0;

While the script still returns the outcome, I’m confused why it has the error? I feel like there’s something fundamental I’m not understanding about running the script in the list?

Thank you for the help and patience!

Trevor

What does the warning say?
That will give us some clues.
Some can just tell by looking at the graph,
but not me :see_no_evil_monkey: :sweat_smile:.

Shoot! I didn’t realize the graph didn’t include the error. It’s:

Asked to convert non-convertible types.

It’s related to the fact that it’s running the Area.Surface on an item that isn’t a surface. In the case of the graph, it’s a line. The intersection is of geometries returns a line when that’s the only connection.

I wonder if you shouldn’t just use the boolean mask node to filter out the non surfaces? :thinking:

List.FilterByBoolMask

I had initially thought about using the Boolean Filter, but my issues was that I still need to keep that “spot” in the list. The Boolean Filter re-arranges the list as if that item in the list had never existed. Once that list structure is gone, it was getting very hard to put it back together in the same way with 0 where the Boolean Filter and removed subitems. But maybe there’s an easy way to do that?

*edit: I think I need the 0 in the list so that if there are not sublist items that are surfaces, the list still keeps a 0 there. Then I know that the intersection for that set of view/room combo didn’t find a solution and I can list that in an output as an error without trying to perform the rest of the graph on that view/room sublist. If the results of a broken view/room are in an out of a Boolean, I was having trouble trying to figure out what view/room was broken because the list order isn’t preserved.

Geometry.Intersect returns a list for every intersection pair.

As such you can use List.RemoveIfNot to strip out any non-surface geometry from the intersection results. Of the only items returned were say curves, then you’ll have an empty list.

Surface.Area in a list of lists of surfaces will return areas in the nested list. Most of those nested lists likely have one surface some might have two. Both work just fine for surface.Area, just make sure the list structure doesn’t change. If the nested list is empty, Surface.Area won’t do anything just pass the empty list along.

Math.Sum will tally the list of areas into one value. If the list has one surface tou’ll get one number in place of the sublist. If it had two or more you’ll also get one number in place of the sublist. And if it has nothing in it… well the sum of an empty list is zero so you’ll get a zero in place of the empty list.

No filtering or if statements needed.

@jacob.small thank you, I’m still struggling with the List.RemoveIfNot, it also removes the sublist item from without keeping a placeholder similar to the Boolean filter. See comparison at the very top of the below graph in sublist [1] . Then I’m not able to correctly match the original list items back against the summary of areas as the sublists now have different counts. Is there a way to use the List.RemoveIfNot, but have it substitute a value instead of removing it? It’s going to be fairly typical for each list to have 2, 3, or 4 items in the sublist, so tracking the order is important to discern which has the item has the associated Surface.Area.

I don’t entirely see the issue, but I think it’s because you’ve flattened for some reason.

Sorry, here’s the graph with notes, hopefully it’s more clear:

Remove the List.Flatten and it should start to make sense.

I finally go there! The geometry has to be in a sublist by itself for the process to work. I was flattening so the data could match my input and I could keep my sublists aligned. But it’s necessary that each geometry be in a alone at their step in the list so the List.RemoveIfNot doesn’t change the overall list structure but just leaves an empty list. Below working nodes with the 0 where the surface geometry is filtered by the List.RemoveIfNot

This is why showing the whole graph with readable nodes helps :sweat_smile: :wink:.