Total bar length query in rebar container

Hi everyone,
By Following the steps in the part of @Organon’s script below related to this post to query rebar container parameters, I noticed in my example below that the parameter Length of each bar take only the curve length itself without adding hooks lengths, this parameter is the base of calculation of Total Bar Length and its logicaly giving a false result in this case

rebar container
# Iterate over the list of lines/vectors.
for i, j in zip(range(0, len(geo)), range(0, len(vect))):
    # Create rebar container.
    containerTypeId = RebarContainerType.GetOrCreateRebarContainerType(doc, "circular_rebar" + str(i+1))
    rebarContainer = RebarContainer.Create(doc, host, containerTypeId)
    # Create curve list.
    totalLength = []
    curv = List[Curve]()
    for c, v in zip(geo[i], vect[j]):
        totalLength.Add(c.ToRevitType().Length)
        curv.Add(c.ToRevitType())
        rebar = Rebar.CreateFromCurves(doc, RebarStyle.Standard, bar_type, None, None, host, v.ToRevitType(), curv, RebarHookOrientation.Left, RebarHookOrientation.Right, True, False)
        rebarContainer.AppendItemFromRebar(rebar)
        doc.Delete(rebar.Id)
        curv.Clear()
    # Update container parameters.
    quantityParameter = rebarContainer.get_Parameter(BuiltInParameter.REBAR_ELEM_QUANTITY_OF_BARS)
    totalLengthParameter = rebarContainer.LookupParameter("Total Bar Length")
    containerParameters = rebarContainer.GetParametersManager()
    containerParameters.AddOverride(quantityParameter.Id, len(geo[i]))
    containerParameters.AddOverride(totalLengthParameter.Id, sum(totalLength))
    rebars.append(rebarContainer)

by analyzing @Organon’s script as shown below, I discovred that Length of each bar is queried before creating rebar itself wich logicaly gives as result the curve length (4600 mm) , so I think that this parameter should be queried after rebar creation so the hooks lengths can be integrated …I tried to fix this issue but I can’t find the exact code for that?

Thanks in advance for your replies.

@REDO10,

I created the code in that way because the rebars were just straight segments witthout hooks, but if you want to get the length of the rebar, just get either the Total Bar Length or Length of each bar parameter after creating them. It’s just a matter of logic.

Regards,

1 Like

@Organon

As I said i n my post, I tried to get the parameter Length of each bar (with Hooks included) but I can’t find the code for that…can you please do that for me?

Thanks.

@Organon
Can I get an answer from you pls?
Thanks.

Since the lengths are being returned as parameter values, couldn’t you pull the values (a…h,H1 and H2) and add them together? I know this doesn’t explain why the Total Bar Length does not account for H1 and H2, but it is a work-around.

1 Like

@staylor

I dont know how to extract these parameters and how to add them together to compute the rebar length?

Have you an idea how to do that?

Thanks.

Here’s a quick and dirty on a per container basis. There may be a better way to range out the alphabet for the parameters, but this works.

paramlist = ["a","b","c","d","e","f","g","h","H1","H2"]
val = []
aval = []
for p in paramlist:
	val.append(container.LookupParameter(p))
for v in val:
	aval.append(v.AsDouble()*304.8)

totallength = sum(aval)
1 Like

@staylor
Did you tried this in an example?..it works?

In my example above the bar length is assigned to the parameter “Longueur de barre” under properties tab…is there a way to extract it directly?

@Organon have you another idea to solve this issue ?

Thanks

Yes, it worked. In your example you stated that you wanted to get the 4600 + 242 for the total bar length. Which in that case would be the sum of parameters “a” and “H1”. I just went ahead and added all the parameters to cover any additional bends that you may have in your rebar.

In my test, “Bar Length” or “Longueur de barre” was not the correct total length of the bar. However, if parameter “Longueur de barre" is length you are looking for, then the only code you need is

length = container.LookupParameter(“Longueur de barre")
totallength = round(length.AsDouble()*304.8)

Again, this is only for one container.

1 Like

@staylor

First of all I’m sorry for this too late feedback!!..I was in a long travel and it was no possible for me to use my computer since my last message and trying what you proposed for me to see how it will go !

I tried your approch and add all rebar parameters to cover any additional bends but it give a wrong result (check my references below)!

for example in the image below the straight length of the rebar is a = 4.80m (real value)…but If I calculate the same parameter a using RevitLookup and Api it gives a = 3.9370 x 0.3048 = 1.20m (which is a wrong value!!?)

as I said in my previous message and as shown in the image below, I noticed that Revit calculate automaticly each rebar length which is called “Longueur de barre ” in my case and which is the base of the total length calculation (I dont know how Revit calculate it ?), so I searched this parameter in all rebar parameters using RevitLookup but I dont found it…is there a way to retrieve it? … @Organon’s help is precious in this case.

container_total_rebar_length.dyn (18.4 KB)
Shaft_rebar.rvt (3.4 MB)

Thanks.

@staylor

I received a notification that you answerd me , but you reply i not visible for me ??

Thanks.

The reply was deleted by the author, perhaps due to an inaccuracy in the post.

1 Like

Yes, I deleted my original post.

See if this is gets you what you need. I commented out your line item for writing the value to the total bar length parameter and added everything after the “rebars.append(rebarContainer)”. When I ran, it worked for me.

# Update container parameters.
quantityParameter = rebarContainer.get_Parameter(BuiltInParameter.REBAR_ELEM_QUANTITY_OF_BARS)
totalLengthParameter = rebarContainer.LookupParameter("Total Bar Length")
containerParameters = rebarContainer.GetParametersManager()
containerParameters.AddOverride(quantityParameter.Id, len(out_V_rebar))
#containerParameters.AddOverride(totalLengthParameter.Id, len(out_V_rebar)* sum(shared_params)*0.3048)

rebars.append(rebarContainer)

for r in rebars:
	qty = r.ItemsCount

paramlist = ["a","b","c","d","e","f","g","h","H1","H2"]
val = []
aval = []
for p in paramlist:
	for r in rebars:
		val.append(r.LookupParameter(p))
for v in val:
	aval.append(v.AsDouble()*304.8)

totallength = sum(aval) * qty * 0.3048

containerParameters.AddOverride(totalLengthParameter.Id, totallength)

EDIT
I don’t know why there is a different parameter value for you when using Revit Lookup. I tested and the values were matching for me. Maybe someone else can provide input on that if you need.

1 Like

Hi @staylor

Your code works but I noticed as I explain in the example below that it does’nt give the correct bar length compared to the real bar length (automaticly calculated by REVIT that I confirmed its length by measuring it as indicated in the example)… the difernence between the two lengths is 3.8 cm !!?

I dont know what’s the exact formula used by REVIT to calculate the real bar length (which is the base of total rebar length calculation) and which it can not be obtained only by summation of the parameters (a, b, c, d…H2) ?

I made a modification to your code using the LookupParameter method to get the real bar length or Length of each bar, named “Longueur de barre” in my case to get the correct Total Bar Length and it works…I dont know if there are more effective solutions then this one and I’ld love that @Organon gives me his perspective on this matter.

updated total bar length calculation
import sys
import clr
import math
import System
from System.Collections.Generic import IList, List 

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

out_V_rebar = IN[0][0]
out_vect = IN[0][1]
cover = IN[1]/0.3048
rebar_type = UnwrapElement(IN[2])
Hook_start = UnwrapElement(IN[3])
Hook_end = UnwrapElement(IN[4])
host= UnwrapElement(IN[5])
spacing = IN[6]/0.3048

rebars = []

TransactionManager.Instance.EnsureInTransaction(doc)
# Create rebar container.
containerTypeId = RebarContainerType.GetOrCreateRebarContainerType(doc, "out_vertical_rebar")
rebarContainer = RebarContainer.Create(doc, host, containerTypeId)
# Create curve list.

crvs = List[Curve]()
for c, v in zip(out_V_rebar, out_vect):
    crvs.Add(c.ToRevitType())    
    rebar = Rebar.CreateFromCurves(doc, RebarStyle.Standard, rebar_type, Hook_start, Hook_end, host, v.ToRevitType(), crvs, RebarHookOrientation.Left, RebarHookOrientation.Right, True, True)
    doc.Regenerate()    
    rebarContainer.AppendItemFromRebar(rebar)
    doc.Delete(rebar.Id)
    crvs.Clear()

# Update container parameters.
quantityParameter = rebarContainer.get_Parameter(BuiltInParameter.REBAR_ELEM_QUANTITY_OF_BARS)
totalLengthParameter = rebarContainer.LookupParameter("Longueur de barre totale")
containerParameters = rebarContainer.GetParametersManager()
containerParameters.AddOverride(quantityParameter.Id, len(out_V_rebar))

rebars.append(rebarContainer)

for r in rebars:
	qty = r.ItemsCount
	bar_length = r.LookupParameter("Longueur de barre").AsDouble()

totallength = bar_length * qty

containerParameters.AddOverride(totalLengthParameter.Id, totallength)
    
TransactionManager.Instance.TransactionTaskDone()

OUT = rebars

final_container_total_rebar_length.dyn (18.2 KB)

Thanks.

Hi @staylor

What do you think about my last thought reflexion to solve this issue?

Thanks.

I think what is happening is Revit is not assigning a parameter to account for the bar extension when using the 180 degree bend. It’s usually 4d to 6d, depending on the geographical location. But the Length of each bar (Longueur de barre) parameter is looking at the total curve length, so it’s accounting for the extension. The test behind this theory is when the bend is 90 degrees at both ends, the sum of all parameter values equals the length of each bar parameter value.

You could use all of the parameters and add a calculation for the extension in your code (doubling when the 180 degree hook is at both ends of course) or stay the course with using the Length of each bar parameter, like you are you doing. I would say that your way would be the more accurate way.

1 Like