Set Layout of rebars to fixe number with Revit API

Hi everybody,

This topic is related to the preor one How to create Rebar From Curves using Revit API and Python in which I want to group the rebars with the same length in a set and as shown in the image below

I tried to use the GetShapeDrivenAccessor() method as indicated in this exemple Error creating rebars from curves in python but I get error related to ArrayLengthand I dont know how to fix it

here my script:

Rebar Set
import sys
import clr
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Structure import*

from System.Collections.Generic import IList, List

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)

doc = DocumentManager.Instance.CurrentDBDocument

# dynamo curves as input
geo = IN[0]
bar_type = UnwrapElement(IN[1])
host = UnwrapElement(IN[2])
vect = IN[3]

rebars = []
temp = []
for i, j in zip(range(0, len(geo)), range(0, len(vect))):
    curv = List[Curve]()
    for c, v in zip(geo[i], vect[j]):
        curv.Add(c.ToRevitType())
        TransactionManager.Instance.EnsureInTransaction(doc)
        rebar = Rebar.CreateFromCurves(doc, RebarStyle.Standard, bar_type, None, None, host, v.ToRevitType(), curv, RebarHookOrientation.Left, RebarHookOrientation.Right, True, False)
        rebar.GetShapeDrivenAccessor().SetLayoutAsFixedNumber(rebar.NumberOfBarPositions, rebar.ArrayLength, rebar.BarsOnNormalSide, rebar.IncludeFirstBar, rebar.IncludeLastBar)
        TransactionManager.Instance.TransactionTaskDone()
        curv = List[Curve]()        
        temp.append(rebar)
    rebars.append(temp)
    temp = []

OUT = rc

Please help me to solve my issue.

Thanks.

1 Like

without a reply, I asked my question here and I get a steps to follow writen in C# as shown below, which I tried to convert to python…my containers are created but they are empty and I dont know where I was wrong??

rebar container in C#
public static RebarContainer CreateDistributedContainer(Document doc, Element host, List<Rebar> rebarList)
		{
			ElementId containerTypeId = RebarContainerType.GetOrCreateRebarContainerType(doc, "RebarContainerName"); // Container type id.
			RebarContainer rebarContainer = RebarContainer.Create(doc, host, containerTypeId); // Create rebar container.

			// Add rebars to cotainer.
			foreach (Rebar rebar in rebarList)
			{
				rebarContainer.AppendItemFromRebar(rebar);
			}

			// Update parameters.
			Parameter quantityParameter = rebarContainer.get_Parameter(BuiltInParameter.REBAR_ELEM_QUANTITY_OF_BARS);
			RebarContainerParameterManager containerParameters = rebarContainer.GetParametersManager();
			containerParameters.AddOverride(quantityParameter.Id, rebarList.Count);

			// The container.
			return rebarContainer;
		}

Please check my code and my screenshot below:

rebars_containers
import sys
import clr
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Structure import*

from System.Collections.Generic import IList, List

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)

doc = DocumentManager.Instance.CurrentDBDocument

# dynamo curves as input
geo = IN[0]
bar_type = UnwrapElement(IN[1])
host = UnwrapElement(IN[2])
vect = IN[3]

rebars = []
temp = []
for i, j in zip(range(0, len(geo)), range(0, len(vect))):
    curv = List[Curve]()
    containerTypeId = RebarContainerType.GetOrCreateRebarContainerType(doc, "circular_rebar" + str(i+1))
    rebarContainer = RebarContainer.Create(doc, host, containerTypeId)
    for c, v in zip(geo[i], vect[j]):
        curv.Add(c.ToRevitType())
        TransactionManager.Instance.EnsureInTransaction(doc)
        rebar = Rebar.CreateFromCurves(doc, RebarStyle.Standard, bar_type, None, None, host, v.ToRevitType(), curv, RebarHookOrientation.Left, RebarHookOrientation.Right, True, False)
        TransactionManager.Instance.TransactionTaskDone()
        curv = List[Curve]()        
    rebarContainer.AppendItemFromRebar(rebar)
    quantityParameter = rebarContainer.get_Parameter(BuiltInParameter.REBAR_ELEM_QUANTITY_OF_BARS)
    containerParameters = rebarContainer.GetParametersManager()
    containerParameters.AddOverride(quantityParameter.Id, curv.Count)    
    rebars.append(rebarContainer)
    
OUT = rebars

Thanks.