List Filter with Single If Statement

Coming from Grasshopper one of the things I use a lot in codes is Filters and Stream Gates and Culls using if statements or sliders to either switch between input/outputs or stop code from running beyond a point if a cull is set to False. This workflow does not require a boolean for every item in the list but just one value.

As you can see this logic somewhat works if the boolean has not been made into a list yet but as soon as this logic comes from something that is in a list it reverts to list structure levels which have no option to change on If node. Or anywhere for that matter, I have found. Also when switching to another list with fewer items it or in this case one Null it just makes it for as many that are in the true list which feels like a wrong and a Bug.

Is it possible to have an option to not only flatten a list but to remove any list data if the item is just a single item so it looks like and works like the True from the number slider code block?

ScopeIf node fails to output false but I don’t know why.

Note, I have not searched all the packages to see if it’s been done I am interested in if there Is a native component or code block to output the required logic. As the fewer packages I am using in my code the easier it is to give to others.

Here’s the code forgot to post it earlier.

LIST FILTER.dyn (34.2 KB)

Make sure your list of items is equal in depth to the list of Booleans.

If you really want a singleton Boolean you can always use a List.FirstItem node to pull the Boolean out of the list.

I think list first item is what i have been looking for. Now just need to solve that when it goes to False it only takes one Null and not the list length, i don’t want to it to compute 1000’s of nulls for the sake if it when one null is all that is required.

This is following on from the previous question somewhat regarding controls via error checking or switching between workflows in a single code.

I knew about make lists equal lengths, that and list structure are the 2 things i see people miss in GH or Dynamo, but that would mean repeating the same Boolean x number of times. I was thinking more along the lines of an Python If Else statement logic like when you have an if active run this portion of code. Maybe coding that in Design script could be the answer.

Pretty easy work-around with dictionaries which makes for easy conversion to a function or custom definition (or a custom node).

Nice, Not worked much with Dictionaries in Design Script yet. Will take a look at these codes. Thanks.

1 Like