In order to create stirrup with hook type and orientation that already specify under rebar shape, I plan on using function under DB.Structure that is Rebar.CreateFromShapeAndCurve this is and required input
Rebar.CreateFromCurvesAndShape(doc, rebarshape, rebartype, starthooktype, endhooktype, host, norm, IList<Curve>, starthookorientation, endhookorientation)
I didnt get what is norm mean, according to RevitAPIDocs.com it is explain that “The normal to the plane that the rebar curves lie on.” and required in form of XYZ(). So I create point with XYZ(1,1,0)
(1,1,0) I presume that this mean the curve that I just create will be in XY plane with no Z am I right?
One more problem is IList is this same as array of curve that can be obtain under this scripts?
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 stir(x1, y1, b, h, cover):
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(1, 1, 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
curve = PolyCurve.Curves(polycurve1)
curve1.append(curve)
count = count + 1
return curve1
pointx = IN[0]
pointy = IN[1]
width = IN[2]
height = IN[3]
covering = IN[4]
curve1 = []
result = stir(pointx, pointy, width, height, covering)
OUT = curve1
This is a result from this scripts
The final problem is that when I combined script that work as shown in above image to scripts that create rebar by shape and curve. I got this error “Exception: A managed exception was thrown by Revit or by one of its external applications.” I dont know which part is error since I have try dissemble code into each function and it work properly. Therefore, my conclusion is my input arent correct according to required input for Rebar.CreateFromShapeAndCurve. This is my Rebar.CreateFromShapeAndCurve scripts.
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 stir(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(1, 1, 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, hooks, hooke, 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 = stir(pointx, pointy, width, height, covering, rebarshape, rebartype, element)
OUT = stirrup_list