Recursive split function

Hi all ,
am trying to split a surface with a list of lines , I did a recursive function that will split the surface in 2 parts with the first curve , one part will go to a new list and the second will be split by the second curve to another 2 pieces and so on , I keep having an error that the index is out of range , any idea why this is happening surface split.dyn (24.5 KB)

You might want to look into Geometry.SplitReursively in the Springs package.

Source code is here: SpringNodes/Geometry.SplitRecursively.dyf at master · dimven/SpringNodes · GitHub

1 Like

Thanx for your reply Jacob but I really want to learn how to do it in pythonscript

In your example, what do you expect for the final output? A list of 6 surfaces (smallest possible pieces)? or a recursion that gives you the interim results as well (e.g. an uncut surface of 3 bays?)

I expect a list of 6 surfaces cut as per the lines locations , but I guess it will not work except I use a recursive method

sorry for replying with this account as my previous account doesn’t work

Per my understanding of your code and expectation (each resulting surface being cut by next cutter line) you do not need a classic recursion algorithm.
This code should give you what you expect:
import clr
clr.AddReference(‘ProtoGeometry’)
from Autodesk.DesignScript.Geometry import *

def Splitter(Surface,cutters):
	output= []
	for i in cutters:
		srf = Geometry.Split(Surface , i)
		#picking the second surface to split
		if len(srf)>1:
			output.append(srf[0]) 
			Surface = srf[1]
			if i == cutters [-1]:
				output.append(srf[1])
	return output
	
OUT = Splitter(IN[0],IN[1])

However, if you want true recursion for more complex situations, you need to rethink the recursion stopper (that is after cutting a surface or surfaces with a cutter line, that line should be removed from the list of cutters and the resulting surfaces should be cut with the remaining cutter lines until all cutter lines are used and removed).

2 Likes

Thank you very much Habdirad this has done it , it was so informative