Hello, not sure if this forum is the correct for questions about revit API. But I try anyway
I am trying to generate rebars with the CreateFromCurves method in Revits API (CreateFromCurves Method). The curves are generated in grasshopper and describes the shape of the rebar. The host element is a structual floor.
The idea is to create a component that works like the Create.FromCurves node in dynamo.
I have made a customized python component that interacts with the Revit API.
Code:
#Creates Rebars in revit from user defined curves
import clr
clr.AddReference(āSystem.Coreā)
clr.AddReference(āRhinoInside.Revitā)
clr.AddReference(āRevitAPIā)
clr.AddReference(āRevitAPIUIā)
clr.AddReference(āRevitServicesā)
from System import Enum, Action, Array
from System.Collections.Generic import List, IList
from RevitServices.Transactions import TransactionManager
import rhinoscriptsyntax as rs
import Rhino
import RhinoInside
import Grasshopper
from Rhino import Collections
from Rhino.Collections import CurveList
from Grasshopper.Kernel import GH_RuntimeMessageLevel as RML
from RhinoInside.Revit import Revit, Convert
from Autodesk.Revit import DB
from Autodesk.Revit import UI
from Autodesk.Revit.DB import Structure, XYZ, Curve, Transaction
from Autodesk.Revit.DB.Structure import Rebar, RebarStyle, RebarBarType, RebarHookType, RebarHookOrientation
#Doc talks to the active Revit document
doc = Revit.ActiveDBDocument
view = doc.ActiveView
cc = DB.Structure
if rebarStyle == 0:
Style = DB.Structure.RebarStyle.Standard
else:
Style = DB.Structure.RebarStyle.StirrupTie
if startHookOrientation == 0:
HookOrientation = DB.Structure.RebarHookOrientation.Left
else:
HookOrientation = DB.Structure.RebarHookOrientation.Right
norm = XYZ(vector[0],vector[1],vector[2])
if Trigger:
t=DB.Transaction(doc,āRebarsareComingā)
t.Start()
try:
rebar = cc.Rebar.CreateFromCurves(doc,Style,rebarType,startHookType,endHookType,hostElement,norm,curves,HookOrientation,HookOrientation,True,True)
t.Commit()
except Exception as txn_err:
error_string = str(txn_err)
print(error_string)
t.RollBack()
The problem is the error message āA managed exception was thrown by Revit or by one of its external applications.ā that occurs everytime I try to run the script. The error dosnt indicate what is wrong, so I have basically no idea where to start the debugging. I was wondering if anyone here have any insight or experience to what may cause the error to occure. Any suggestion is appreciated!
This is how it looks like:
I have tried to give the curves as Polyline curves and as exploded line like curves. generatingReinforcementprob.gh (87.8 KB)