Get rebar geometry in Dynamo

Currently, in my project, many of the rebar are placed inside the elements (walls, slabs, framing,etc…) however, they do not have the correct hosts.

What I’m trying to do is that, get the geometry of the rebar, check which element the rebar is intersecting with, then will set that elements as the host.

The set host step can be done easily with some python script, however, when I tried to get the geometry of the rebar, it just return an empty list. I have tried many time, but get nothing beside that. Is there anyway to get the geometry (solid) of a selected rebar?

Hey @Tholm_MTH
In researching I came across the post below. Within this post @Einar_Raknes provided a way to get the curve of the rebar. You don’t get the actual geometry of the rebar, but if you get the solid geometry of the element, you should be able to use the Geometry.DoesIntersect node to verify if the curve intersects the solid.

My test


Code from python script

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

#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 = rebar.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
1 Like

Dear Staylor,

It looks like the script wont run if the number of rebar of the input is bigger than 1.

I tried to adjust the script, but it seems it wont work.

Is there any other solution?

You can get the location (center point) of rebar instead of its geometry. It is much faster.

Hi newshunhk,

I tried the solution from Mr Staylor above, and the script from this thread too: Location of rebar - #10 by Einar_Raknes

But it seems like it wont run with revit 2021, with multiple rebars as input.

I modified the code. I haven’t quite grasped everything about working with lists in python, so I am using list count option. You also need to set the lacing to longest on the Geometry.DoesIntersect node.

Updated python script 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)
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])
count = IN[1]
mpo = MultiplanarOption.IncludeAllMultiplanarCurves
curves = []

#Get info from rebar
if count > 1:
	for e in rebar:
		revitCurve = e.GetCenterlineCurves(0,0,0,mpo,0)
		curves.append(r.ToProtoType(True) for r in revitCurve)
else:
	revitCurve = rebar.GetCenterlineCurves(0,0,0,mpo,0)
	curves.append(r.ToProtoType(True) for r in revitCurve)

OUT = curves
1 Like

Hi. I’m new to Dynamo. After some reading, I found a Python script from [jostein_olsen] updated from [Einar_Raknes]. I wrapped it into a custom node so I can do lacing. It takes all the centerlines in a rebar set(not just for the first rebar in the set). Also works for more than one rebar set at once by setting the lacing to longest.
RebarGetCenterlines.dyf (6.0 KB)

2 Likes

I used to create custom definitions for that very reason also, but now I try to resolve it within the code itself. Makes it easier when troubleshooting errors. Also, I create scripts for quite a few users at my company and having to keep up with who has what definitions and if they have the latest and greatest definitions was proving to be a pain. Just my two cents.

Thank you for the help, Staylor

I’m now able to set the host for rebar, and here is the script in case any other users need.
Set Host for Rebar.dyn (65.9 KB)