Hi everyone,
I filled up my container with my creted rebars, but I noticed that the parameter " length of each bar " is missing as shown in the image below, so how can I set it please?
rebars
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_curv = IN[0][0].ToRevitType()
out_path = IN[0][1].ToRevitType()
iner_curv = IN[0][2].ToRevitType()
iner_path = IN[0][3].ToRevitType()
cover = IN[1]/0.3048
rebar_type = UnwrapElement(IN[2])
Hook_type = UnwrapElement(IN[3])
host= UnwrapElement(IN[4])
spacing = IN[5]/0.3048
# compute the rotation angle
def rebar_rotation(circle, space):
sweepAngle = (space * 360) / (circle.Radius * 2 * math.pi)
return sweepAngle
out_angle = rebar_rotation(out_path, spacing)
iner_angle = rebar_rotation(iner_path, spacing)
# rotated rebars count
out_count = int(math.ceil(360/out_angle))
iner_count = int(math.ceil(360/iner_angle))
# get rotated curves
out_rot_curvs = []
for i in range(0, out_count):
a= i*out_angle
rot_curv = Transform.CreateRotation(XYZ.BasisZ, a*2*math.pi/360)
out_curvs = out_curv.CreateTransformed(rot_curv)
out_rot_curvs.append(out_curvs)
iner_rot_curvs = []
for i in range(0, iner_count):
a= i*iner_angle
rot_curv = Transform.CreateRotation(XYZ.BasisZ, a*2*math.pi/360)
iner_curvs = iner_curv.CreateTransformed(rot_curv)
iner_rot_curvs.append(iner_curvs)
#create horizontal line needed to create normal vector
out_line =Line.CreateBound(out_curv.GetEndPoint(0), iner_curv.GetEndPoint(0))
iner_line =Line.CreateBound(iner_curv.GetEndPoint(0), out_curv.GetEndPoint(0))
rot_90 = Transform.CreateRotation(XYZ.BasisZ, math.pi/2)
out_line = out_line.CreateTransformed(rot_90)
iner_line = iner_line.CreateTransformed(rot_90)
#get rotated lines
out_Vect = []
for i in range(0, out_count):
a= i*out_angle
rot_vect = Transform.CreateRotation(XYZ.BasisZ, a*2*math.pi/360)
out_vect = out_line.CreateTransformed(rot_vect)
out_Vect.append(out_vect)
iner_Vect = []
for i in range(0, iner_count):
a= i*iner_angle
rot_vect = Transform.CreateRotation(XYZ.BasisZ, a*2*math.pi/360)
iner_vect = iner_line.CreateTransformed(rot_vect)
iner_Vect.append(iner_vect)
#create normal vectors
out_Vect = [(i.GetEndPoint(0) - i.GetEndPoint(1)).Normalize() for i in out_Vect]
iner_Vect = [(i.GetEndPoint(0) - i.GetEndPoint(1)).Normalize() for i in iner_Vect]
# create rebars
out_rebars = []
iner_rebars = []
TransactionManager.Instance.EnsureInTransaction(doc)
containerTypeId = RebarContainerType.GetOrCreateRebarContainerType(doc, "iner_V_rebar" )
rebarContainer = RebarContainer.Create(doc, host, containerTypeId)
iner_V_crv = List[Curve]()
for c, v in zip(iner_rot_curvs, iner_Vect):
iner_V_crv.Add(c)
iner_V_rebar = Rebar.CreateFromCurves(doc, RebarStyle.Standard, rebar_type, Hook_type, Hook_type, host, v, iner_V_crv, RebarHookOrientation.Left, RebarHookOrientation.Right, True, True)
rebarContainer.AppendItemFromRebar(iner_V_rebar)
doc.Delete(iner_V_rebar.Id)
iner_V_crv.Clear()
quantityParameter = rebarContainer.get_Parameter(BuiltInParameter.REBAR_ELEM_QUANTITY_OF_BARS)
containerParameters = rebarContainer.GetParametersManager()
containerParameters.AddOverride(quantityParameter.Id, len(iner_rot_curvs))
iner_rebars.append(rebarContainer)
TransactionManager.Instance.TransactionTaskDone()
OUT = iner_rebars
Please check my references below
rebars_container.dyn (18.3 KB)
Shaft_rebar.rvt (3.4 MB)
Thanks.