# Split beam at multiple indexes using beam.Split(index) method

**URL:** <https://forum.dynamobim.com/t/split-beam-at-multiple-indexes-using-beam-split-index-method/50186>\
**Category:** Revit\
**Tags:** revit, python, dynamo\
**Created:** [May 4, 2020, 11:46am UTC](https://forum.dynamobim.com/t/split-beam-at-multiple-indexes-using-beam-split-index-method/50186 "2020-05-04T11:46:41Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![AdamOs](https://avatars.discourse-cdn.com/v4/letter/a/a4c791/32.png) [@AdamOs](https://forum.dynamobim.com/u/AdamOs)\
**Post date:** [May 4, 2020, 11:46am UTC](https://forum.dynamobim.com/t/split-beam-at-multiple-indexes-using-beam-split-index-method/50186/1 "2020-05-04T11:46:41Z")

</div>

Hi,  
Is there any way to split beam using list of floats (from 0 to 1 excluded) to split beam at multiple points?  
Im trying to loop through the list but each subsequent iteration divides the already divided beam.

Here is the piece of code im trying to use

```
TransactionManager.Instance.EnsureInTransaction(doc)
for index in list:
if beam.CanSplit and 0 < index < 1:
    beam.Split(index)
TransactionManager.Instance.TransactionTaskDone()
```

---

<div class="post-metadata">

**Author:** ![cgartland](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/cgartland/32/45378_2.png) [@cgartland](https://forum.dynamobim.com/u/cgartland)\
**Post date:** [May 4, 2020, 1:12pm UTC](https://forum.dynamobim.com/t/split-beam-at-multiple-indexes-using-beam-split-index-method/50186/2 "2020-05-04T13:12:39Z")

</div>

Hi Adam,

Would you be able to provide the rest of your code for some additional context?

---

<div class="post-metadata">

**Author:** ![AdamOs](https://avatars.discourse-cdn.com/v4/letter/a/a4c791/32.png) [@AdamOs](https://forum.dynamobim.com/u/AdamOs)\
**Post date:** [May 4, 2020, 1:38pm UTC](https://forum.dynamobim.com/t/split-beam-at-multiple-indexes-using-beam-split-index-method/50186/3 "2020-05-04T13:38:05Z")

</div>

I’m using element.Split(float) method whitch takes an float parameter, e.g. 0.5 will divide beam in half.  
The issue here is that when I try to iterate with a list of indexes,  
e.g - I want to divide beam into three beams, so my list will be [0.3 , 0.6].  
But after first iteration I have two new beams and second iteration divides one of them - not the original one.  
Is there any other API method that splits element by points maybe?

```
    doc = DocumentManager.Instance.CurrentDBDocument
    beam = UnwrapElement(IN[0])
    list = IN[1]

    TransactionManager.Instance.EnsureInTransaction(doc)
    for index in lista:

        if beam.CanSplit and 0 < index < 1:
            beam.Split(index)

    TransactionManager.Instance.TransactionTaskDone()
```

---

<div class="post-metadata">

**Author:** ![cgartland](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/cgartland/32/45378_2.png) [@cgartland](https://forum.dynamobim.com/u/cgartland)\
**Post date:** [May 4, 2020, 3:27pm UTC](https://forum.dynamobim.com/t/split-beam-at-multiple-indexes-using-beam-split-index-method/50186/4 "2020-05-04T15:27:26Z")

</div>

There doesn’t seem to be a straightforward solution to this, although I don’t think it’s impossible. FamilyInstance.Split() returns the ElementId of the new element, so you should be able to get the new element from the document and split it separately. I assume that splitting a beam at 0.3 will leave the 0.7 part as the new element, but you should confirm this. A recursive function is probably the best approach here as it should continue to split the newly generated beams until there are no parameters left. What complicates this even further is that the document may have to be regenerated after the new elements are created and that the new beams have a normalized curve domain as well. For example, if you want to divide a beam into 4 equal sections, the first beam is split at 1/4, the second is split at 1/3, and the third is split at 1/2.

---

<div class="post-metadata">

**Author:** ![c.poupin](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/c.poupin/32/89152_2.png) [@c.poupin](https://forum.dynamobim.com/u/c.poupin)\
**Post date:** [May 4, 2020, 9:40pm UTC](https://forum.dynamobim.com/t/split-beam-at-multiple-indexes-using-beam-split-index-method/50186/5 "2020-05-04T21:40:57Z")

</div>

Hello  
a solution with the creation of new FamilyInstance (s) and removal of the old beam

```
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Structure import *

clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.GeometryConversion)

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument

def splitBeam(elem, lstParaPt):
    def getPts():
        #create list of point
        curvB = elem.Location.Curve
        ptCurv = [curvB.Evaluate(x, True) for x in lstParaPt]
        ptCurv.extend([curvB.GetEndPoint(x) for x in range(0,2)])
        ptCurv.sort(key = lambda x : curvB.GetEndPoint(0).DistanceTo(x))
        return ptCurv
    #main function  
    lstPt = getPts()
    outBeam = []
    famSymb = elem.Symbol 
    lvl = elem.Host
    TransactionManager.Instance.EnsureInTransaction(doc)
    for idx, pt in enumerate(lstPt):
        if idx > 0:
            curv = Line.CreateBound(lstPt[idx -1], pt)
            newbeam = doc.Create.NewFamilyInstance(curv, famSymb, lvl, StructuralType.Beam)
            outBeam.append(newbeam)
    doc.Delete(elem.Id)     
    TransactionManager.Instance.TransactionTaskDone()   
    return outBeam, lstPt
    
beam = UnwrapElement(IN[0])
lstParam = IN[1]
loc = beam.Location
if isinstance(loc, LocationCurve):
    outBeam , lstPt = splitBeam(beam, lstParam)
OUT = outBeam 

```

 ![multisplit Beam](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/8/b/8b7cf3e006b931548d3953bfc7cec4164dac9c1a.png)

---

<div class="post-metadata">

**Author:** ![AdamOs](https://avatars.discourse-cdn.com/v4/letter/a/a4c791/32.png) [@AdamOs](https://forum.dynamobim.com/u/AdamOs)\
**Post date:** [May 5, 2020, 9:36am UTC](https://forum.dynamobim.com/t/split-beam-at-multiple-indexes-using-beam-split-index-method/50186/6 "2020-05-05T09:36:58Z")

</div>

Thanks! Could you show your refrences? Cause I seem to miss a refrence using your code.

Generally I was avoiding any “replacement” solution cause I wanted to keep original parameteres and FamilyInstance.Split() method seems to keep them.

I came up with idea to convert indexes to a target ones - e.g. Division to 4 parts indexes are [0.75, 0.5, 0.25]. After conversion [0.75, 0.666, 0.5].

And it works fine.

---

<div class="post-metadata">

**Author:** ![c.poupin](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/c.poupin/32/89152_2.png) [@c.poupin](https://forum.dynamobim.com/u/c.poupin)\
**Post date:** [May 5, 2020, 7:22pm UTC](https://forum.dynamobim.com/t/split-beam-at-multiple-indexes-using-beam-split-index-method/50186/7 "2020-05-05T19:22:03Z")

</div>

code updated with “imports”

---

<div class="post-metadata">

**Author:** ![paris](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/paris/32/144289_2.png) [@paris](https://forum.dynamobim.com/u/paris)\
**Post date:** [May 13, 2020, 10:24am UTC](https://forum.dynamobim.com/t/split-beam-at-multiple-indexes-using-beam-split-index-method/50186/8 "2020-05-13T10:24:53Z")

</div>

> [@c.poupin](#):
>
> creation of new FamilyInstance (s) and removal of the old beam

Hi @c.poupin and @cgartland , it’s possible to split multiple beams at multiple index or multiple intersection points without deleting and create a new family? Split recursively to keep the properties from the originals beams like C#?

---

<div class="post-metadata">

**Author:** ![AdamOs](https://avatars.discourse-cdn.com/v4/letter/a/a4c791/32.png) [@AdamOs](https://forum.dynamobim.com/u/AdamOs)\
**Post date:** [May 13, 2020, 11:10am UTC](https://forum.dynamobim.com/t/split-beam-at-multiple-indexes-using-beam-split-index-method/50186/9 "2020-05-13T11:10:30Z")

</div>

Hi @paris. It is possible, as I said above - I came with idea to split beams recursively while keeping parameters from the original (not deleting original and creating new objects like @c.poupin proposed).  
Try using my code below - it takes intersection indexes of original beam and the beam you want to split. (Try also filtering indexes that are very close to 1 or 0)

```
doc = DocumentManager.Instance.CurrentDBDocument
beam = UnwrapElement(IN[0])
list = IN[1]
list = filter(None, lista)
list.sort(reverse = True)
list_new = [] 
count = 1
while len(list) > count:
    list_new.append((list[count]/list[count-1]))
    count += 1
list_new.insert(0, lista[0])
TransactionManager.Instance.EnsureInTransaction(doc)
for index in list_new:
    if beam.CanSplit and 0 < index < 1:
        beam.Split(index)
TransactionManager.Instance.TransactionTaskDone()

```

It works for single selection but you could also add few lines to loop through all selected beams.  
To find indexes at which beam is intersected you can use this for example:

 ![obraz](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/a/9/a90cbe32c67a3768893777e76a98b614bc680063.png)

---

<div class="post-metadata">

**Author:** ![paris](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/paris/32/144289_2.png) [@paris](https://forum.dynamobim.com/u/paris)\
**Post date:** [May 13, 2020, 11:19am UTC](https://forum.dynamobim.com/t/split-beam-at-multiple-indexes-using-beam-split-index-method/50186/10 "2020-05-13T11:19:30Z")

</div>

and thanks for your efforts

---

<div class="post-metadata">

**Author:** ![paris](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/paris/32/144289_2.png) [@paris](https://forum.dynamobim.com/u/paris)\
**Post date:** [May 13, 2020, 11:47am UTC](https://forum.dynamobim.com/t/split-beam-at-multiple-indexes-using-beam-split-index-method/50186/11 "2020-05-13T11:47:03Z")

</div>

Hi @AdamOs , yes,I have the same problem with python to split pipes and ducts on multiple intersection points (of multiple floors), I can split multiple pipes and ducts on multiple points ( intersection points between pipes or ducts and one floor) or with only one pipe (or duct) with multiple floors, but it doesn’t work properly with multiple pipes, ducts and intersection points on floors.  
For ducts I used:  
[https://www.revitapidocs.com/2017/baeec9be-b43d-d378-31b9-453432d44bfb.htm](https://www.revitapidocs.com/2017/baeec9be-b43d-d378-31b9-453432d44bfb.htm)  
and for pipes:  
[https://www.revitapidocs.com/2017/3c302b80-d1f8-0e17-154a-b809cad2e545.htm](https://www.revitapidocs.com/2017/3c302b80-d1f8-0e17-154a-b809cad2e545.htm)  
Tank you

---

<div class="post-metadata">

**Author:** ![paris](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/paris/32/144289_2.png) [@paris](https://forum.dynamobim.com/u/paris)\
**Post date:** [May 13, 2020, 11:50am UTC](https://forum.dynamobim.com/t/split-beam-at-multiple-indexes-using-beam-split-index-method/50186/12 "2020-05-13T11:50:55Z")

</div>

> [@AdamOs](#):
>
> you could also add few lines to loop through al

Hi @AdamOs, nice, I will try your method and give you a feedback, thank you

---

<div class="post-metadata">

**Author:** ![c.poupin](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/c.poupin/32/89152_2.png) [@c.poupin](https://forum.dynamobim.com/u/c.poupin)\
**Post date:** [May 13, 2020, 8:09pm UTC](https://forum.dynamobim.com/t/split-beam-at-multiple-indexes-using-beam-split-index-method/50186/13 "2020-05-13T20:09:28Z")

</div>

a recursive split version…without deletion 😃

```
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *

clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.GeometryConversion)

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument

def splitBeam(elem, lstParaPt):
	def getPts(curvB):
		#create list of point
		ptCurv = [curvB.Evaluate(x, True) for x in lstParaPt]
		#sort by distance with end point of Curve
		ptCurv.sort(key = lambda x : curvB.GetEndPoint(1).DistanceTo(x))
		return ptCurv 
	#main function  
	curvB = elem.Location.Curve
	lstPt = getPts(curvB)
	outBeam = []
	TransactionManager.Instance.EnsureInTransaction(doc)
	for pt in lstPt:
		lenBeam = curvB.Length 
		param = (curvB.GetEndPoint(0).DistanceTo(pt)) / lenBeam
		newBeam = elem.Split(param)
		outBeam.append(newBeam)
		doc.Regenerate()
	TransactionManager.Instance.TransactionTaskDone()   
	return outBeam, lstPt, curvB.GetEndPoint(0).ToPoint()
	
beam = UnwrapElement(IN[0])
lstParam = IN[1]
loc = beam.Location
if isinstance(loc, LocationCurve):
	outBeam , lstPt, startPt = splitBeam(beam, lstParam)
OUT = outBeam, startPt 

```

 ![recursivesplit](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/6/5/65ac052f40466c041e78ab9fb3ff2675c97f1f5d.jpeg)

---

<div class="post-metadata">

**Author:** ![paris](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/paris/32/144289_2.png) [@paris](https://forum.dynamobim.com/u/paris)\
**Post date:** [May 14, 2020, 3:38pm UTC](https://forum.dynamobim.com/t/split-beam-at-multiple-indexes-using-beam-split-index-method/50186/14 "2020-05-14T15:38:20Z")

</div>

Great @c.poupin well done ! thank you.  
Can also work with points instead using a list of floats?  
I have to modify your code to work with break method for split pipes and ducts at points (intersection with floors).  
Have a nice day !

---

<div class="post-metadata">

**Author:** ![c.poupin](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/c.poupin/32/89152_2.png) [@c.poupin](https://forum.dynamobim.com/u/c.poupin)\
**Post date:** [May 16, 2020, 5:07pm UTC](https://forum.dynamobim.com/t/split-beam-at-multiple-indexes-using-beam-split-index-method/50186/15 "2020-05-16T17:07:49Z")

</div>

hello @paris  
try this

```
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *

clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.GeometryConversion)

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument

def splitBeam(elem, lstPt):
	curvB = elem.Location.Curve
	#sort by distance with end point of Curve
	lstPt.sort(key = lambda x : curvB.GetEndPoint(1).DistanceTo(x))
	outBeam = []
	TransactionManager.Instance.EnsureInTransaction(doc)
	for pt in lstPt:
		lenBeam = curvB.Length 
		param = (curvB.GetEndPoint(0).DistanceTo(pt)) / lenBeam
		newBeam = elem.Split(param)
		outBeam.append(newBeam)
		doc.Regenerate()
	TransactionManager.Instance.TransactionTaskDone()   
	return outBeam, lstPt, curvB.GetEndPoint(0).ToPoint()
	
beam = UnwrapElement(IN[0])
lstDynPt = IN[1]
#convert dynamo points to Revit Point
lstPt = [x.ToXyz() if isinstance(x, Autodesk.DesignScript.Geometry.Point) else x for x in lstDynPt]
loc = beam.Location
if isinstance(loc, LocationCurve):
	outBeam , lstPt, startPt = splitBeam(beam, lstPt)
OUT = outBeam, startPt
```

---

<div class="post-metadata">

**Author:** ![paris](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/paris/32/144289_2.png) [@paris](https://forum.dynamobim.com/u/paris)\
**Post date:** [May 17, 2020, 6:41pm UTC](https://forum.dynamobim.com/t/split-beam-at-multiple-indexes-using-beam-split-index-method/50186/16 "2020-05-17T18:41:11Z")

</div>

Hello @c.poupin  
great, your code work perfectly, like a charm for split one beam at multiple points !  
Thank you !  
Now I’m looking to resolve the issue with multiple beams…  
Cheers, have a nice day !

---

<div class="post-metadata">

**Author:** ![caoyecheng](https://avatars.discourse-cdn.com/v4/letter/c/bb73d2/32.png) [@caoyecheng](https://forum.dynamobim.com/u/caoyecheng)\
**Post date:** [August 17, 2021, 2:33pm UTC](https://forum.dynamobim.com/t/split-beam-at-multiple-indexes-using-beam-split-index-method/50186/17 "2021-08-17T14:33:18Z")

</div>

hello ，can you correct my python script，many thanks  
using revit2018 dynamo 2.0.3  
i want to deal the beams at one time  
i’ve try to modify your code，but it could not run  
also， i have no idea about----AttributeError: ‘List[object]’ object has no attribute ‘Location’  
and thanks again

```auto
beam = UnwrapElement(IN[0])
lstParam = IN[1]
cc=[]
count=0
loc = beam.Location
for i in beam:
	if isinstance(loc, LocationCurve):
		outBeam , lstPt = splitBeam(beam[count], lstParam[count])
	cc.append(outBeam )
	count +=1
	
OUT = cc

```

 ![20210817222541](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/e/f/eff31b069cbe93cf486e1c2546d2c95fd4b3ff70.png)

---

<div class="post-metadata">

**Author:** ![Deniz\_Maral](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/deniz_maral/32/80323_2.png) [@Deniz\_Maral](https://forum.dynamobim.com/u/Deniz_Maral)\
**Post date:** [August 17, 2021, 2:45pm UTC](https://forum.dynamobim.com/t/split-beam-at-multiple-indexes-using-beam-split-index-method/50186/18 "2021-08-17T14:45:13Z")

</div>

take loc into the loop and do like that:  
loc = i.Location

---

<div class="post-metadata">

**Author:** ![c.poupin](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/c.poupin/32/89152_2.png) [@c.poupin](https://forum.dynamobim.com/u/c.poupin)\
**Post date:** [August 17, 2021, 9:03pm UTC](https://forum.dynamobim.com/t/split-beam-at-multiple-indexes-using-beam-split-index-method/50186/19 "2021-08-17T21:03:08Z")

</div>

> [@caoyecheng](#):
>
> hello ，can you correct my python script，many thanks

hello @caoyecheng  
In addition of the @Deniz_Maral 's post

```auto
beam = UnwrapElement(IN[0])
lstParam = IN[1]
cc=[]
count=0
for i in beam:
	loc = i.Location
	if isinstance(loc, LocationCurve):
		outBeam , lstPt = splitBeam(beam[count], lstParam[count])
	cc.append(outBeam )
	count +=1
	
OUT = cc

```

> [@caoyecheng](#):
>
> using revit2018 dynamo 2.0.3

and you can update your version of Dynamo 2.0.3 → 2.0.4  
[DynamoInstall2.0.4.exe](https://dyn-builds-data.s3-us-west-2.amazonaws.com/DynamoInstall2.0.4.exe)  
[https://dynamobuilds.com/](https://dynamobuilds.com/)

---

<div class="post-metadata">

**Author:** ![caoyecheng](https://avatars.discourse-cdn.com/v4/letter/c/bb73d2/32.png) [@caoyecheng](https://forum.dynamobim.com/u/caoyecheng)\
**Post date:** [August 21, 2021, 2:43pm UTC](https://forum.dynamobim.com/t/split-beam-at-multiple-indexes-using-beam-split-index-method/50186/20 "2021-08-21T14:43:26Z")

</div>

thank you very much

[Next page](https://forum.dynamobim.com/t/split-beam-at-multiple-indexes-using-beam-split-index-method/50186.md?page=2)
