Split Beam At Parameter Points

Hi all!

I am trying to split a beam by creating new beams at the points using NewFamilyInstance. For some reason it isn’t working and doesn’t give any particular error.

Would appreciate if someone can help figure this out! :muscle:

import clr
import sys

import System
from System import Array
from System.Collections.Generic import *
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager 
from RevitServices.Transactions import TransactionManager 

clr.AddReference('RevitAPI')
clr.AddReference('RevitAPIUI')

import Autodesk 
from Autodesk.Revit.DB import *
from Autodesk.Revit.UI import *

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication 
app = uiapp.Application 
uidoc = uiapp.ActiveUIDocument

elems = UnwrapElement(IN[0]) if isinstance(UnwrapElement(IN[0]),list) else [UnwrapElement(IN[0])]

parameters = IN[1]

lvl = UnwrapElement(IN[2])
strType = UnwrapElement(IN[3])
beam = elems[0]

#Get beam symbol
symbol = beam.Symbol



#Begin transaction
try:
    TransactionManager.Instance.EnsureInTransaction(doc)
    
    #Get beam curve and start/end points
    beamCurve = beam.Location.Curve
    point1 = beamCurve.GetEndPoint(0)
    point2 = beamCurve.GetEndPoint(1)
    
    #Create points at parameters
    points = [beamCurve.Evaluate(p,True) for p in parameters]
    
    #Drop first and last points 
    splitPoints = points[1:-1]
    
    #define start point of first beam
    startPoint = point1
    beams = []
    dynBeams = []
    for point in splitPoints:
        #create line with start and end points
        line = Line.CreateBound(startPoint,point)
        beam = doc.Create.NewFamilyInstance(line,symbol,lvl,strType)
        
        beams.append(beam)
        #####dynBeams.append(beam.ToDSType())
        
        startPoint = point
    
    #Create last beam    
    line = Line.CreateBound(startPoint,point2)
    beam = doc.Create.NewFamilyInstance(line,symbol,lvl,strType)
    beams.append(beam)
    #####dynBeams.append(beam.ToDSType())


#End transaction
finally:
    TransactionManager.Instance.TransactionTaskDone()

OUT =  beams

Hi @zviLNBRQ for split revit elements, try look into genius loci how it can be done :wink: there is a python for split…ducts,pipes, walls, columns, beams

2 Likes

@zviLNBRQ replace your strType variable with StructuralType.Beam

beam = doc.Create.NewFamilyInstance(line,symbol,lvl,StructuralType.Beam)

Also, you might want to delete the original beam with a doc.Delete() call at the end.

1 Like

Doesn’t the node StructuralType.Beam that I used fulfill this function?

Thanks for the response sovitek!
Are you referring to the method FamilyInstance.Split?

@zviLNBRQ My guess is StructuralType enum in Dynamo is a bit mixed up. According to Revit documentation, the int value for Beam is 1 and for NonStructural is 0. However, the current situation is Beam 0 and NonStructural 4 (which is Footing). I call the function with NonStructural 0, it yields a full list of null as well.

And I don’t think unwrapping enum is necessary.

1 Like