Wrong rebar Hook direction for angle 90°

@Thomas_Mahon , @Organon

To find a solution to this issue that only occurs in my case, I posted another thread Normal vector Revit API trying to understand vectors class in Revit API and how I can create them directly using API instead of Protogeometry to avoid any conflict, thus seeing how things go…by the way, this issue keeps recurring only when Hook orientation is set to 90°, so what’s the exact explanation to this matter and what is its solution (PS: this has also happend here)

please chek my updated references below:

st script: rebar_curve
import sys
import clr
import math
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

clr.AddReference('RevitNodes')
import Revit
from Revit.Elements import Element

element = IN[0]
cover = IN[1]
rebar_type = IN[2]
spacing = IN[3]

geo = element.Geometry()
surfaces = geo[0].Explode()

s_area = []

for i in surfaces:
    s_area.append(i.Area)
    
S_area = ["%0.2f"%(round(i,2)) for i in s_area]
    
surf = []
surf_area = set()

for s, a in zip(surfaces, S_area):
    if a not in surf_area and S_area.count(a) == 2:
        surf.append(s)
        surf_area.add(a)
        

out_V_crv = surf[1].GetIsoline(0, 1).Explode()[0]
out_direct = out_V_crv.Direction

if out_direct.Z > 0 :
    out_V_crv = out_V_crv
else:
    out_V_crv = out_V_crv.reverse()
    
vect = out_direct.Cross(Vector.ByCoordinates(0,1,0))  
out_V_rebar = out_V_crv.Translate(vect, cover)

overlap_length = rebar_type.GetParameterValueByName("Diamètre de barre")*50/1000
out_V_rebar = out_V_rebar.ExtendEnd(overlap_length)

out_path = surf[1].GetIsoline(1, 0).Explode()[0]
out_path = out_path.Offset(-cover)
    
OUT = out_V_rebar, out_path
2nd script: 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

curv = IN[0][0].ToRevitType()
out_path = IN[0][1].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

angle = rebar_rotation(out_path, spacing)

# rotated rebars count
count = int(math.ceil(360/angle))

# get rotated curves
rot_curvs = []
for i in range(0, count):   
    a= i*angle
    rot_curv = Transform.CreateRotation(XYZ.BasisZ, a*2*math.pi/360)
    rebar_curve = curv.CreateTransformed(rot_curv)
    rot_curvs.append(rebar_curve)
    
#create horizontal line needed to create normal vector
curv1 = curv.CreateOffset(spacing, XYZ(0,1,0))
line =Line.CreateBound(curv.GetEndPoint(0), curv1.GetEndPoint(0))
rot_90 = Transform.CreateRotation(XYZ.BasisZ, math.pi/2)
line = line.CreateTransformed(rot_90)

#get rotated lines
Vect = []
for i in range(0, count):   
    a= i*angle
    rot_vect = Transform.CreateRotation(XYZ.BasisZ, a*2*math.pi/360)
    vect = line.CreateTransformed(rot_vect)
    Vect.append(vect)
    
#create normal vectors
Vect = [(i.GetEndPoint(0) - i.GetEndPoint(1)).Normalize() for i in Vect]

# create rebars
rebars = []
TransactionManager.Instance.EnsureInTransaction(doc)
for c, v in zip(rot_curvs, Vect):
    out_V_crv = List[Curve]()
    out_V_crv.Add(c)
    out_V_rebar = Rebar.CreateFromCurves(doc, RebarStyle.Standard, rebar_type, Hook_type, Hook_type, host, v, out_V_crv, RebarHookOrientation.Left, RebarHookOrientation.Right, True, True)
    rebars.append(out_V_rebar)
TransactionManager.Instance.TransactionTaskDone()

OUT = rebars

updated_rebars.dyn (16.0 KB)

Thanks.