Split Curve by Boolean List

Good morning everyone!

I have a problem in my script which i do not know how to solve, so i hope someone else has a good insight/ idea for this problem :slight_smile:

I have two inputs, a line/ points and a list of booleans. Now i want to split this line on each first false boolean/ each last boolean (seen in my example below).

How would i approach this?
Thanks in advance!

SplitCurvesByBooleanSample.dyn (42.0 KB)

could you make a small diagram of the desired result
I did not understand quite well

The diagram are the lines on the bottom. The colored lines are the prefered output :slight_smile:

this is what you are looking for

Hello
a solution with a Python generator

import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
import Autodesk.DesignScript.Geometry as DS

def ranges(lstBool, lstPoints):
	#get index false
	idxFalse = [idx for idx, i in enumerate(lstBool) if not i]
	#return 1st point
	yield lstPoints[0]
	#init start end
	start, end = idxFalse[0], idxFalse[0]
	count = start
	for item in idxFalse:
		if not count == item:
			yield lstPoints[start]
			yield lstPoints[end]
			#re-init start end
			start, end = item, item
			count = item
		end = item
		count += 1
	yield lstPoints[start]
	yield lstPoints[end]
	#return last point
	yield lstPoints[-1]	

lstPoints = IN[0]
lstBool = IN[1]
out = []
lstPtToLine = [x for x in ranges(lstBool, lstPoints)]
for idx, i in enumerate(lstPtToLine):
	if idx > 0:
		line = DS.Line.ByStartPointEndPoint(lstPtToLine[idx - 1], i)
		out.append(line)

OUT = out
1 Like

Yes this is exactly what i need! Thank you very much!!

hi @c.poupin

Thank you for your input aswell!
The only problem which will occur with this approach is that curved lines will be straight lines from points