- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi everyone, @longt61
I'm using Dynamo inside Revit and IronPython 2.7 , and I'm attempting to create longitudinal rebars (Bottom and Top rebar) for a stright beam which is oriented in +X direction as you can see in the image below, and this by using CreateFromCurves Method.
As you can see in the image below, in my code I grabed the South beam face where its FaceNormal is XYZ(0,-1,0), then to create rebars I set normal vector to be the opposite of FaceNormal and equal to XYZ(0,1,0)...however I'm conused and unable to set correct RebarHookOrientation for both ends in Top rebar, which are always oriented toward UP (+Z) instead of Down (-Z), even though I tried to set all possible orientation combinations in my code (Left/Right, Left/Left, Right/Right, Right/Left)!!
Please check my code below and guide me to well understand RebarHookOrientation priciple to be able to solve my issue
Here my code:
import clr
import sys
import System
from System.Collections.Generic import IList, List
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Structure import *
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.AddReference('RevitServices')
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
top_bar_type = UnwrapElement(IN[0])
btm_bar_type = UnwrapElement(IN[1])
hook_type = UnwrapElement(IN[2])
def get_solid(beam):
options = Options()
options.IncludeNonVisibleObjects = False
options.DetailLevel = ViewDetailLevel.Fine
geoElement = beam.get_Geometry(options)
for geoObj in geoElement:
if isinstance(geoObj, Solid) and geoObj.Volume > 0:
return geoObj
elif isinstance(geoObj, GeometryInstance):
inst_geo = geoObj.GetInstanceGeometry()
for g in inst_geo:
if isinstance(g, Solid) and g.Volume > 0:
return g
return None
def get_side_face_edges_and_normal(solid, direction, vector):
for face in solid.Faces:
normal = face.FaceNormal
if not normal.IsAlmostEqualTo(XYZ.BasisZ) \
and not normal.IsAlmostEqualTo(XYZ.BasisZ.Negate()) \
and not normal.IsAlmostEqualTo(direction) \
and not normal.IsAlmostEqualTo(direction.Negate()) \
and normal.IsAlmostEqualTo(vector):
edges = [e for loop in face.EdgeLoops for e in loop]
curvesorted = sorted(edges, key=lambda x: x.AsCurve().Length)
btmLine, topLine = sorted(curvesorted[2:], key=lambda x: x.AsCurve().GetEndPoint(0).Z)
return [[btmLine, topLine]], normal # Wrap in nested list for consistency
return None, None
def get_opposite_beam_faces(beam):
beam_curve = beam.Location.Curve
direction = beam_curve.Direction
vector = XYZ(0, -1, 0) # Target face normal (North)
solid = get_solid(beam)
if not solid:
return None, None
return get_side_face_edges_and_normal(solid, direction, vector)
# Collect beams
all_beams = FilteredElementCollector(doc)\
.OfCategory(BuiltInCategory.OST_StructuralFraming)\
.WhereElementIsNotElementType()\
.ToElements()
rebars = []
rebar_curves = []
with Transaction(doc, "create rebars") as t:
t.Start()
beam = all_beams[0]
beam_loc = beam.Location.Curve
beam_direction = beam_loc.Direction
max_edges, face_normal = get_opposite_beam_faces(beam)
normal = face_normal.Negate()
for btm_edge, top_edge in max_edges:
# Create fresh curve lists for each bar
btm_crv = btm_edge.AsCurve()
top_crv = top_edge.AsCurve()
btm_rebar_curv = List[Curve]()
top_rebar_curv = List[Curve]()
btm_rebar_curv.Add(btm_crv)
top_rebar_curv.Add(top_crv)
btm_rebar = Rebar.CreateFromCurves(
doc, RebarStyle.Standard,
btm_bar_type, hook_type, hook_type,
beam, normal, btm_rebar_curv,
RebarHookOrientation.Left, RebarHookOrientation.Right,
True, True
)
rebars.append(btm_rebar)
rebar_curves.append(btm_crv.ToProtoType())
top_rebar = Rebar.CreateFromCurves(
doc, RebarStyle.Standard,
top_bar_type, hook_type, hook_type,
beam, normal, top_rebar_curv,
RebarHookOrientation.Left, RebarHookOrientation.Right,
True, True
)
rebars.append(top_rebar)
rebar_curves.append(top_crv.ToProtoType())
t.Commit()
OUT = rebars, rebar_curves
Any help would be appreciated.
Thanks.
Solved! Go to Solution.