I got confuse on how Rebar.CreateFromShapeAndCurve work

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

Hello, @somphon!

I ran into a similar issue when trying to place a U rebar at the edge of a slab using the Autodesk.Revit.DB.Structure.Rebar.CreateFromCurvesAndShape method. I spent time on this too, so don’t be discouraged - you are not alone with this problem :slight_smile: Sooner or later everything will work!

  1. about the normal - no, the normal that the method requests is a vector from the plane (your stirrup lies in this plane)
    That is, if the stirrup lies in the XY plane, therefore the normal goes along Z, that is, the normal vector has coordinates (0, 0, 1).

However, if we do create points, then I would suggest creating a list with the points of your rebar. Then create a polyline based on them, request a plane from the polyline and request a normal from the plane. This way you will not need to think about which vector to write in the program if the figure is flat:

listPt = [  ]
listPt.append(pt_0)
listPt.append(pt_1)
listPt.append(pt_2)
listPt.append(pt_3)
listPt.append(pt_4)

vector = PolyCurve.ByPoints(listPt).BasePlane().Normal.ToXyz()
  1. about the list with curves - the problem is that the method requires several lines of the Revit type. Accordingly, I would suggest doing this:

    line_0 = Autodesk.DesignScript.Geometry.Line.ByStartPointEndPoint(pt_0, pt_1)
    line_1 = Autodesk.DesignScript.Geometry.Line.ByStartPointEndPoint(pt_1, pt_2)
    line_2 = Autodesk.DesignScript.Geometry.Line.ByStartPointEndPoint(pt_2, pt_3)
    line_3 = Autodesk.DesignScript.Geometry.Line.ByStartPointEndPoint(pt_3, pt_4)

    listL = [ ]
    listL.append(line_0.ToRevitType())
    listL.append(line_1.ToRevitType())
    listL.append(line_2.ToRevitType())
    listL.append(line_3.ToRevitType())

Be sure to convert the line to a Revit type using the .ToRevitType () method. Exception: “A managed exception was thrown by Revit or by one of its external applications” occurs because you pass the wrong line type to CreateFromCurvesAndShape.

In this case, pt0…4 are points created through: Autodesk.DesignScript.Geometry.Point.ByCoordinates(…, …, …) earlier.

Use listL instead of curve1. I had a problem with this.

If I did not understand something in your question or did not explain it clearly - sorry, I use Google Translate :slight_smile:

1 Like