Get index of true and false blocks

Hello,

the following script does not work completely as it should, maybe someone of you has an idea to help me out :slight_smile:

It is comparing distances between objects. If the distance is <600 it should do one thing and if distance is >600 it should do another thing. This are the trues and falses in the middle codeblock. All works pretty good when there is only one false in between the trues.

When there are 2 consecutive falses (line 2 or 3) the script should add a “1” at the “correct” index. I’m having trouble to insert the “1” at the correct index…

I hope the lines 2 and 3 give you an idea of what I’m planning to do.

My approach was to group “true” and “false” if they are sequential. However, I don’t know if there’s a node to accomplish that, so I did this step with python and finished with the dynamo nodes.

Here’s the final result of your 3 examples:

from itertools import groupby

group = groupby(IN[0])

OUT = [list(g) for k,g in group]
2 Likes

Amazing :slight_smile:
Thank you so much. It works like a charm.