Updating Rebar containers parameters

Hi All, @Organon , @c.poupin

In my model attached below I created two rebar containers which are grouped in the main container…I was able to fill my rebars in those containers according to their faces, but something is wrong in this part of the script “Rebars creation


and I can’t update correctly the Total bar length parameter of the containers (only one container is updated as shown in the image below)

any help will be appreciable

Kindly check my refrences below

Shaft_rebar.rvt (3.4 MB)
Total_length_rebar_container.dyn (34.1 KB)

Thanks.

@staylor

Can you take a look here pls?

Thanks

The code below in place of what you have boxed out, will write the value to each container parameter. However, it writes the same value for both. I just can’t figure out how to iterate the total lengths to each corresponding parameter correctly. I noticed that both parameters have the exact same Id, so maybe that has something to do with it. Maybe someone else can provide input on that. Getting ready to head out for the weekend. If you don’t get it before Monday, I will look at it some more then.

params=[]
for r in rebarContainer:
	params.append(r.GetParametersManager())
	for l in total_length:
		for p in params:
			p.AddOverride(totalLengthParameter.Id, l)

EDIT

I even tried it this way. Funny thing. If you look at the parameters of each container individually, the total bar length is exactly the same. However, if you select both containers, the total bar length parameter says “varies”.

params=[]
totalLengthParameter=[]
for r in rebarContainer:
	params.append(r.GetParametersManager())
	totalLengthParameter.append(r.LookupParameter("Total Bar Length"))
	for l in total_length:
		for p in params:
			for t in totalLengthParameter:
				p.AddOverride(t.Id, l)
1 Like

@staylor

I finally found the solution and all parameters are computed and filled correctely in their fields within their correponding containers

the solution was to add/Override containers parameters within the main loop at the same level of containers list, so it allows me to iterate between containers themselves and filling their parameters even before filling them in rebars container

here the updated part of the code:

rebars = []

TransactionManager.Instance.EnsureInTransaction(doc)

containerTypeId = [RebarContainerType.GetOrCreateRebarContainerType(doc, c ) for c in container_name]
rebarContainer = [RebarContainer.Create(doc, host, r) for r in  containerTypeId]

for i, j in zip(range(0, len(curvs)), range(0, len(Vect))):
    rebar_curv = List[Curve]()
    for c, v in zip(curvs[i], Vect[j]):
        rebar_curv.Add(c)
        rebar = Rebar.CreateFromCurves(doc, RebarStyle.Standard, rebar_type[i], St_Hook[i], end_Hook[i], host, v, rebar_curv, RebarHookOrientation.Left, RebarHookOrientation.Right, True, True)
        doc.Regenerate()
        rebarContainer[i].AppendItemFromRebar(rebar)
        doc.Delete(rebar.Id)
        rebar_curv.Clear()
    quantityParameter = rebarContainer[i].get_Parameter(BuiltInParameter.REBAR_ELEM_QUANTITY_OF_BARS)
    qty = rebarContainer[i].ItemsCount
    totalLengthParameter = rebarContainer[i].LookupParameter("Longueur de barre totale")
    bar_length = rebarContainer[i].LookupParameter("Longueur de barre").AsDouble()
    Length_each_bar_Parameter = rebarContainer[i].LookupParameter("Length of each bar")
    containerParameters = rebarContainer[i].GetParametersManager()
    containerParameters.AddOverride(quantityParameter.Id, qty)
    containerParameters.AddOverride(Length_each_bar_Parameter.Id, bar_length)
    containerParameters.AddOverride(totalLengthParameter.Id, bar_length*qty)
    rebars.append(rebarContainer[i])

TransactionManager.Instance.TransactionTaskDone()

OUT = rebars

However, I dont know if there are more effective solutions or a better reflexion to write the code than this one and I’ld love that @Organon or @c.poupin gives me their perspective on this matter.

Thanks.

1 Like