Internal error when creating columns stirrup rebars

Internal error when creating columns stirrup rebars

REDO10
Collaborator Collaborator
86 Views
0 Replies
Message 1 of 1

Internal error when creating columns stirrup rebars

REDO10
Collaborator
Collaborator

Hi All, @kummari_teja @longt61 @naveen_kumar_t

 

I’m using Dynamo inside Revit 2023 and I'm  attempting to create stirrup rebars for the columns shown in the image below. However, I received an internal error message, and I’m not sure what caused it. Could it be related to a RebarHookOrientation issue when the column is transformed?

 

column_Transform.png

 

image.png

 

As I descibed in the image below, I tick “Include hooks in Rebar Shape definition”,...are my settings correct?

 

reinforcement.png

Please check my attached 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 StructuralType, RebarBarType, RebarShape, RebarHookType,Rebar, RebarHookOrientation, RebarStyle, RebarCoverType

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


# get covers parameters by face 
cover_faces = {
    "Top": BuiltInParameter.CLEAR_COVER_TOP,
    "Bottom": BuiltInParameter.CLEAR_COVER_BOTTOM,
    "Other": BuiltInParameter.CLEAR_COVER_OTHER
}

cover_types = list(FilteredElementCollector(doc).OfClass(RebarCoverType).ToElements())

# get existing covers type
def get_cover_type(distance):

    for ct in cover_types:
        if abs(ct.CoverDistance - distance) < 1e-6:
            return ct
    name = "Enrobage_{} cm".format(distance / 0.0328084)
    new_ct = RebarCoverType.Create(doc, name, distance)
    cover_types.append(new_ct)
    return new_ct

# set covers distance from user input
def set_column_covers(column, top, btm, side):
    # Convert cm → feet
    cover_cm = {"Top": top, "Bottom": btm, "Other": side}
    cover_ft = {face: cover_cm[face] * 0.0328084 for face in cover_cm}

    # Assign covers
    for face, bip in cover_faces.items():
        param = column.get_Parameter(bip)
        if param and param.StorageType == StorageType.ElementId:
            ct = get_cover_type(cover_ft[face])
            if ct:
                param.Set(ct.Id)

# get updated covers from user input
def get_column_covers(column):
    
    result = {}
    for face, bip in cover_faces.items():
        param = column.get_Parameter(bip)
        if param and param.StorageType == StorageType.ElementId:
            ct = doc.GetElement(param.AsElementId())
            if isinstance(ct, RebarCoverType):
                result[face] = ct.CoverDistance
    return result
    
# get solid geometry from column
def get_solid(column):
    options = Options()
    options.IncludeNonVisibleObjects = False
    options.DetailLevel = ViewDetailLevel.Fine
    geoElement = column.get_Geometry(options)
    for g in geoElement:
        if isinstance(g, GeometryInstance):
            inst_geo = g.GetInstanceGeometry()
    return next((g for g in inst_geo if isinstance(g, Solid) and g.Volume > 0), None)
    
# define stirrups curves for the column
def stirrup_curves(column, solid, covers):
    curves = []
    side_cover = covers.get("Other")
    btm_cover = covers.get("Bottom")
    base_face = next((f for f in solid.Faces if f.FaceNormal.IsAlmostEqualTo(XYZ.BasisZ.Negate())), None)
    norm = base_face.FaceNormal
    curveloop = base_face.GetEdgesAsCurveLoops()[0]
    curveloop1 = CurveLoop.CreateViaOffset(curveloop, side_cover, norm.Negate())
    trans = Transform.CreateTranslation(XYZ.BasisZ.Multiply(btm_cover))
    curveloop1 = CurveLoop.CreateViaTransform(curveloop1, trans)
    for c in curveloop1:
        curves.append(c)    
    return curves


columns = list(FilteredElementCollector(doc)\
    .OfCategory(BuiltInCategory.OST_StructuralColumns)\
    .WhereElementIsNotElementType()\
    .ToElements())

offset_curves = []

with Transaction(doc, "Set columns Covers") as t:
    t.Start()
    for c in columns:
        set_column_covers(c, 4.5, 6, 3.5)
    t.Commit()

rebar_types = (FilteredElementCollector(doc)
        .OfCategory(BuiltInCategory.OST_Rebar)
        .WhereElementIsElementType()
        .WherePasses(ElementClassFilter(RebarBarType))
        .ToElements())
        
rebar_shapes = (FilteredElementCollector(doc)
        .OfCategory(BuiltInCategory.OST_Rebar)
        .WhereElementIsElementType()
        .WherePasses(ElementClassFilter(RebarShape))
        .ToElements())

#shape_00 = next((s for s in rebar_shapes if s.Name == "00"), None)


bar_type = next((r for r in rebar_types if r.LookupParameter('Diamètre de barre').AsValueString() == "12 mm"), None)

bar_type1 = next((r for r in rebar_types if r.LookupParameter('Diamètre de barre').AsValueString() == "6 mm"), None)


hook_types = FilteredElementCollector(doc) \
    .OfCategory(BuiltInCategory.OST_Rebar) \
    .WhereElementIsElementType() \
    .WherePasses(ElementClassFilter(RebarHookType)) \
    .ToElements()

hook_90 = next((h for h in hook_types if Element.Name.GetValue(h) == "Standard - 90 deg"), None)

hook_135 = next((h for h in hook_types if Element.Name.GetValue(h) == "Standard - 135 deg"), None)



with Transaction(doc, "create stirrups") as t:
    t.Start()
    for col in columns:
        solid = get_solid(col)
        covers = get_column_covers(col)
        top_cover, btm_cover, side_cover = covers["Top"], covers["Bottom"], covers["Other"]
        curvs = stirrup_curves(col, solid, covers)
        L = col.LookupParameter('Longueur').AsDouble()
        s = 0.15 * 0.3048
        d = L - top_cover - btm_cover
        stirup_curves = List[Curve](curvs)
        rebar = Rebar.CreateFromCurves(
            doc,
            RebarStyle.StirrupTie,
            bar_type1, 
            hook_135, 
            hook_135, 
            col,          
            XYZ.BasisZ,        
            curvs,      
            RebarHookOrientation.Left,
            RebarHookOrientation.Left,
            True,
            True
            )
        rebar.GetShapeDrivenAccessor().SetLayoutAsMaximumSpacing(s, d, True, True, True)    
            
    t.Commit()

OUT = 0

 

Please check my attached model file below:

 

Any help would be appreciated.

 

Thanks.

 

0 Likes
87 Views
0 Replies
Replies (0)