# Wrong rebar Hook orientation REVIT API

**URL:** <https://forum.dynamobim.com/t/wrong-rebar-hook-orientation-revit-api/89094>\
**Category:** Developers\
**Tags:** python, dynamo\
**Created:** [April 30, 2023, 10:08am UTC](https://forum.dynamobim.com/t/wrong-rebar-hook-orientation-revit-api/89094 "2023-04-30T10:08:25Z")\
**Posts on this page:** 1\
**Showing post:** 31

<div class="post-metadata">

**Author:** ![c.poupin](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/c.poupin/32/89152_2.png) [@c.poupin](https://forum.dynamobim.com/u/c.poupin)\
**Post date:** [May 4, 2023, 8:26am UTC](https://forum.dynamobim.com/t/wrong-rebar-hook-orientation-revit-api/89094/31 "2023-05-04T08:26:02Z")

</div>

Hello,  
after some test here is an approach by selecting a face, I could not explain everything because the structure is really out of my area of ​​​​expertise, and this part of the API seems really very complex to understand

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/8/c/8c8098eaf1cd297d4c3d6417a7a9f2fa71a1079a.png)

![test rebar on beam](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/d/b/db8890775aca55e078d6642ba01bdf777dd6c9b3.gif)

```auto
import sys
import clr
import math
from System.Collections.Generic import IList, List

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

clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *
from Autodesk.Revit.UI.Selection import *

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
uidoc = uiapp.ActiveUIDocument

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

Btm_bar_type = UnwrapElement(IN[0])
Top_bar_type = UnwrapElement(IN[1])
bar_Hook_type = UnwrapElement(IN[2])
cover = IN[3]/0.3048
spacing = 0.10/0.3048

TaskDialog.Show("Selection", "Pick a Face")
ref = uidoc.Selection.PickObject(ObjectType.Face, "Pick a Face")
# get Face Geometry
sel_elem = doc.GetElement(ref)
tf1 = sel_elem.GetTotalTransform()
face = sel_elem.GetGeometryObjectFromReference(ref)
# get the instance of Face Normal (Transformed)
faceNormal = tf1.OfVector(face.FaceNormal)
#beam_width
width = doc.GetElement(sel_elem.GetTypeId()).LookupParameter("b").AsDouble()
# get beam direction
beam_direction = sel_elem.Location.Curve.Direction
#
# create an transfrom for onternal offset 
tf2 = DB.Transform.CreateTranslation(face.FaceNormal.Negate() * 0.1)
curveLoop = face.GetEdgesAsCurveLoops()[0]
# move curveloop inside the beam
# compute a transformation translation
offset_curvloop = DB.CurveLoop.CreateViaOffset(curveLoop, -0.1, face.FaceNormal)
# apply the fully transform to get the instance of Geometry
offset_curvloop = DB.CurveLoop.CreateViaTransform(offset_curvloop, tf1.Multiply(tf2))
# get top and bottom curves
curvesorted = sorted(offset_curvloop, key = lambda x : x.Length)
bottomLine, topLine = sorted(curvesorted[2:], key = lambda x : x.GetEndPoint(0))

TransactionManager.Instance.ForceCloseTransaction()
t = Transaction(doc, "Script Rebar")
t.Start()

# compute the normal for Rebar
if faceNormal.CrossProduct(beam_direction).IsAlmostEqualTo(XYZ(0,0,-1)):
	normT = topLine.Direction.CrossProduct(XYZ.BasisZ)
	normB = topLine.Direction.CrossProduct(XYZ.BasisZ)
else:
	normT = topLine.Direction.CrossProduct(XYZ.BasisZ).Negate()
	normB = topLine.Direction.CrossProduct(XYZ.BasisZ).Negate()

Top_rebar = Rebar.CreateFromCurves(doc, 
								RebarStyle.Standard, 
								Btm_bar_type, 
								bar_Hook_type, 
								bar_Hook_type, 
								sel_elem, 
								normT, 
								List[DB.Curve]([topLine]), 
								RebarHookOrientation.Left, 
								RebarHookOrientation.Right, 
								True, 
								True)
								
Top_rebar.GetShapeDrivenAccessor().SetLayoutAsFixedNumber(math.ceil((width-2*cover)/spacing), width-2*cover, True, True, True)

								
Btm_rebar = Rebar.CreateFromCurves(doc, 
								RebarStyle.Standard, 
								Btm_bar_type, 
								bar_Hook_type, 
								bar_Hook_type, 
								sel_elem, 
								normB, 
								List[DB.Curve]([bottomLine]), 
								RebarHookOrientation.Left, 
								RebarHookOrientation.Right, 
								True, 
								True)
								
Btm_rebar.GetShapeDrivenAccessor().SetLayoutAsFixedNumber(math.ceil((width-2*cover)/spacing), width-2*cover, True, True, True)

t.Commit()
t.Dispose()

OUT = sel_elem, face, bottomLine.ToProtoType(), topLine.ToProtoType()

```

---

_[View the full topic](https://forum.dynamobim.com/t/wrong-rebar-hook-orientation-revit-api/89094)._
