# Recursive split function

**URL:** <https://forum.dynamobim.com/t/recursive-split-function/38975>\
**Category:** Developers\
**Created:** [July 31, 2019, 9:07pm UTC](https://forum.dynamobim.com/t/recursive-split-function/38975 "2019-07-31T21:07:48Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![arcosamaq](https://avatars.discourse-cdn.com/v4/letter/a/b77776/32.png) [@arcosamaq](https://forum.dynamobim.com/u/arcosamaq)\
**Post date:** [July 31, 2019, 9:07pm UTC](https://forum.dynamobim.com/t/recursive-split-function/38975/1 "2019-07-31T21:07:48Z")

</div>

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](https://forum.dynamobim.com/uploads/short-url/lMRUKC2QnVg44ltJUkMEdz3WaCu.dyn) (24.5 KB)

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [July 31, 2019, 9:13pm UTC](https://forum.dynamobim.com/t/recursive-split-function/38975/2 "2019-07-31T21:13:40Z")

</div>

You might want to look into [Geometry.SplitReursively](https://dynamonodes.com/2016/12/16/geometry-splitrecursively/) in the Springs package.

Source code is here: [SpringNodes/Geometry.SplitRecursively.dyf at master · dimven/SpringNodes · GitHub](https://github.com/dimven/SpringNodes/blob/master/Nodes/Geometry.SplitRecursively.dyf)

---

<div class="post-metadata">

**Author:** ![arcosamaq](https://avatars.discourse-cdn.com/v4/letter/a/b77776/32.png) [@arcosamaq](https://forum.dynamobim.com/u/arcosamaq)\
**Post date:** [August 3, 2019, 6:57pm UTC](https://forum.dynamobim.com/t/recursive-split-function/38975/3 "2019-08-03T18:57:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![habdirad](https://avatars.discourse-cdn.com/v4/letter/h/ecd19e/32.png) [@habdirad](https://forum.dynamobim.com/u/habdirad)\
**Post date:** [August 4, 2019, 6:52am UTC](https://forum.dynamobim.com/t/recursive-split-function/38975/4 "2019-08-04T06:52:20Z")

</div>

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?)

---

<div class="post-metadata">

**Author:** ![osama.qadan](https://avatars.discourse-cdn.com/v4/letter/o/f6c823/32.png) [@osama.qadan](https://forum.dynamobim.com/u/osama.qadan)\
**Post date:** [August 4, 2019, 7:17am UTC](https://forum.dynamobim.com/t/recursive-split-function/38975/5 "2019-08-04T07:17:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![osama.qadan](https://avatars.discourse-cdn.com/v4/letter/o/f6c823/32.png) [@osama.qadan](https://forum.dynamobim.com/u/osama.qadan)\
**Post date:** [August 4, 2019, 7:17am UTC](https://forum.dynamobim.com/t/recursive-split-function/38975/6 "2019-08-04T07:17:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![habdirad](https://avatars.discourse-cdn.com/v4/letter/h/ecd19e/32.png) [@habdirad](https://forum.dynamobim.com/u/habdirad)\
**Post date:** [August 4, 2019, 9:16pm UTC](https://forum.dynamobim.com/t/recursive-split-function/38975/7 "2019-08-04T21:16:21Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![arcosamaq](https://avatars.discourse-cdn.com/v4/letter/a/b77776/32.png) [@arcosamaq](https://forum.dynamobim.com/u/arcosamaq)\
**Post date:** [August 5, 2019, 3:46pm UTC](https://forum.dynamobim.com/t/recursive-split-function/38975/8 "2019-08-05T15:46:13Z")

</div>

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