Get Rebar Centerlines

Hey @Kulkul

I tried to use your custom node, but there appears a error. What can I do to get locations’s rebars?

Hi @brenofilipe

Which Dynamo and Revit Version you’re using?

My Revit is 2021 and Dynamo is 2.5.0.7586

@brenofilipe Try this code:

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

ProcessLists = lambda function, lists: [ProcessLists(function, item) if isinstance(item, list) else function(item) for item in lists]
ApplyFunction = lambda func, objs: ProcessLists(func, objs) if isinstance(objs, list) else [func(objs)]

def Unwrap(item):
    return UnwrapElement(item)
    
if isinstance(IN[0], list):
	rebar = ProcessLists(Unwrap, IN[0])
else:
	rebar = Unwrap(IN[0])

def task(rc):
	return [r.ToProtoType(True) for r in rc.GetCenterlineCurves(0,0,0,MultiplanarOption.IncludeAllMultiplanarCurves,0)]

OUT = ApplyFunction(task,rebar)

3 Likes

Thank you very much @Kulkul, this works!!

@Kulkul your code works fine with a list of rebars, however when I use it in a set of rebars with maximum spacing layout, it only shows me the first bar.

I found the code below that shows all rebars of the set, but it does not work with a list of rebars.

import clr

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

clr.AddReference(‘RevitNodes’)
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)

clr.AddReference(‘RevitServices’)
import RevitServices
from RevitServices.Persistence import DocumentManager

doc = DocumentManager.Instance.CurrentDBDocument
view = doc.ActiveView

#Convert input from dynamo to revit
rebar = UnwrapElement(IN[0])
rebarShp = rebar.GetShapeDrivenAccessor()

#Set options
mpo = MultiplanarOption.IncludeAllMultiplanarCurves

#Get info from rebar
numOfBars = rebar.NumberOfBarPositions
quantity = rebar.Quantity
layoutRule = rebar.LayoutRule

if numOfBars > 1:
#Find visible bars and get their centerline curves transformed to correct position
centerlineCurves =
for i in range(numOfBars):
if not rebar.IsBarHidden(view,i):
posTransform = rebarShp.GetBarPositionTransform(i)
revitCurve = [c.CreateTransformed(posTransform) for c in rebar.GetCenterlineCurves(0,0,0,mpo,0)]
centerlineCurves.append([r.ToProtoType(True) for r in revitCurve])

else:
centerlineCurves = [r.ToProtoType(True) for r in rebar.GetCenterlineCurves(0,0,0,mpo,0)]
OUT = centerlineCurves

Could you explain me how can I addapt your code so it can show all rebars of a set?

Hi! When I go the Revit API page and search for GetCenterlineCurves it seems like it only takes three arguments and they are all of boolean type. Would you please explain how your method works with five arguments? I have tried to apply this script in my own project but keep getting an error related to number of arguments.

Thank you:)