I try to create stirrup using
Rebar.CreateFromCurvesAndShape(Document, RebarShape, RebarBarType, RebarHookType (Start Hook), RebarHookType (End Hook), Element, XYZ (norm), IList<Curves>, RebarHookOrientation (Start), RebarHookOrientation (End))
but I got this error Exception: A managed exception was thrown by Revit or by one of its external applications. What is the cause for this error because I already try to check each of my input to these function it work just fine but when used together with these function it shown this error.
This is my full code
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
# Import Revit Services
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
import Autodesk.Revit.DB as DB
from Autodesk.Revit.DB import Curve as RCurve
from Autodesk.Revit.DB.Structure import *
clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *
clr.AddReference("RevitNodes")
import Revit
from Revit.Elements import *
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
import System
import System.Array
from System.Collections.Generic import *
#get the document
doc = DocumentManager.Instance.CurrentDBDocument
#Function
def str(x1, y1, b, h, cover, shape, type, host):
nx1 = x1 - (b / 2) + cover
nx2 = x1 + (b / 2) - cover
ny1 = y1 - (h / 2) + cover
ny2 = y1 + (h / 2) - cover
nz1 = 0
count = 0
point_list = []
outLine = []
while (count < 1):
#Create Point
pt1 = XYZ(nx1, ny1, nz1).ToPoint()
pt2 = XYZ(nx2, ny1, nz1).ToPoint()
pt3 = XYZ(nx2, ny2, nz1).ToPoint()
pt4 = XYZ(nx1, ny2, nz1).ToPoint()
pt6 = XYZ(0, 0, 0)
#Create Point List
point_list.append(pt1)
point_list.append(pt2)
point_list.append(pt3)
point_list.append(pt4)
#Use Point List Create PolyCurves
polycurve1 = PolyCurve.ByPoints(point_list, True)
outLine.append(polycurve1)
#Make polycurve in form of curve
curve1 = PolyCurve.Curves(polycurve1)
#Get rebar hook from rebar shape
shook = RebarShape.GetDefaultHookAngle(shape, 0)
ehook = RebarShape.GetDefaultHookAngle(shape, 1)
#Get orient data from rebar shape
orients = RebarShape.GetDefaultHookOrientation(shape, 0)
oriente = RebarShape.GetDefaultHookOrientation(shape, 1)
#Somehow the result from GetDefaultHookAngle is result as 135, which is angle but I preferred to get ID. Therefore, add constant to equal value as ID
id1 = shook + 93441
id2 = ehook + 93441
#Assign int as element id
hookid1 = ElementId(id1)
hookid2 = ElementId(id2)
#Get rebar hook family by id
hooks = doc.GetElement(hookid1)
hooke = doc.GetElement(hookid2)
#UnwrapElement
uhooks = UnwrapElement(hooks)
uhooke = UnwrapElement(hooke)
#Start Transaction
TransactionManager.Instance.EnsureInTransaction(doc)
#Create Stirrup base on curves and shape
#Function : Rebar.CreateFromCurvesAndShape(Document, RebarShape, RebarBarType, RebarHookType (Start Hook), RebarHookType (End Hook), Element, XYZ (norm), IList<Curves>, RebarHookOrientation (Start), RebarHookOrientation (End))
stirrup1 = Rebar.CreateFromCurvesAndShape(doc, shape, type, uhooks, uhooke, host, pt6, curve1, orients, oriente)
stirrup_list.append(stirrup1)
#End
TransactionManager.Instance.TransactionTaskDone()
count = count + 1
return stirrup_list
pointx = IN[0]
pointy = IN[1]
width = IN[2]
height = IN[3]
covering = IN[4]
rebarshape = UnwrapElement(IN[5])
rebartype = UnwrapElement(IN[6])
element = UnwrapElement(IN[7])
stirrup_list = []
result = str(pointx, pointy, width, height, covering, rebarshape, rebartype, element)
OUT = stirrup_list
Testing stirrup scripts_r9.dyn (21.2 KB)