I have a question regarding the use of “filter by boolean mask”. I want to split up a list by a boolean, perform operations on each half of the list, and then recombine them into a single list maintaining the original order. What’s the best way to do this? In Grasshopper, I would do this with a merge component because the dispatch tool would maintain their original paths.
Hi Dennis,
there are probably better ways of doing it but when i was facing the same issue, i dealt with it like this :
A bit of python seems to be the most straightforward way to do this:
It should be easy to replicate this in DS, but the solution will end up being longer.
Hi Dimitar, i try to use your solution but it does’t work. i don’t understend where i make mistake. Can you help me?
Traceback (most recent call last):
File “”, line 10, in
IndexError: index out of range: 0
I was trying to achieve the same as the Original Poster but none of the suggested answers did quite that so here’s how I managed to get it working.
You can copy the Python Script from the following Gist: https://gist.github.com/StudioLE/73a6f47f6419ef0f0a4445699f11ea91
You can check out the code of the List.MergeByBoolMask
node from springs:
The springs node is for a different user case, it always takes elements from the front of the list.
In my solution when an element is selected from one list the same index is ignored in the other list.
So given two lists:
A and B
and the mask:
true, false, true, true, false
The output list would be:
A[0], B[1], A[2], A[3], B[4]
Whereas springs would give you
A[0], B[0], A[1], A[2], B[1]
@Laurence_Elsdon Would this work for you?
Indeed it does, thanks! That’s an impressively concise bit of shorthand. Do you know of any decent docs that teach these kind of tricks?
The only place I can recall having seen this is here :
https://primer.dynamobim.org/07_Code-Block/7-3_shorthand.html
If since then you have found other places to discover these types of little codes I am also interested!