I’m using the Revit API method to create rebar free form curve as indicated here, but I’m stuck how to iterate at the same time in the Normal verctor list (Normal_vect) and its corresponding curve list (crvs) to be able to create the rebar doc…I thought to use zip function but I dont know how can I write the correct syntax to iterate in each sublists nested in my two lists (I want to keep the structure of my list)
here my graph:
Note: ignore the error until I haven’t correctly write the correct syntax of the function zip to iterate between curves list and vector list
Here my code:
Rebar
import sys
import clr
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
doc = DocumentManager.Instance.CurrentDBDocument
# dynamo curves as input
geo = IN[0]
bar_type = UnwrapElement(IN[1])
host = UnwrapElement(IN[2])
vect = IN[3]
# converting dynamo curves to Revit curves
crvs = []
temp = []
for l in range(0, len(geo)):
for c in geo[l]:
temp.append(c.ToRevitType())
crvs.append(temp)
temp = []
# get nornal vectors of each curve
Normal_vect = []
for l in range(0, len(vect)):
for v in vect[l]:
temp.append(v.ToRevitType())
Normal_vect.append(temp)
temp = []
rebars = []
TransactionManager.Instance.EnsureInTransaction(doc)
for i in range(0, len(crvs)):
for j in crvs[i]:
rebars = [Rebar.CreateFromCurves(doc, RebarStyle.Standard, bar_type, None, None, host, j, i, RebarHookOrientation.Left, RebarHookOrientation.Right, True, False) for i, j in zip(crvs, Normal_vect)]
TransactionManager.Instance.TransactionTaskDone()
OUT = rebars
I tried something using zip function but I dont know if the iteration over curves and vectors outcome, because I get an error message:
for more details, please find below my last code, dyn file and Revit file
Note: for surface selection you should select the model bottom surface
Rebar
import sys
import clr
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
doc = DocumentManager.Instance.CurrentDBDocument
# dynamo curves as input
geo = IN[0]
bar_type = UnwrapElement(IN[1])
host = UnwrapElement(IN[2])
vect = IN[3]
# converting dynamo curves to Revit curves
crvs = []
temp = []
for l in range(0, len(geo)):
for c in geo[l]:
temp.append(c.ToRevitType())
crvs.append(temp)
temp = []
# get nornal vectors of each curve
Normal_vect = []
for l in range(0, len(vect)):
for v in vect[l]:
temp.append(v.ToRevitType())
Normal_vect.append(temp)
temp = []
TransactionManager.Instance.EnsureInTransaction(doc)
# iterate over sublist in Normal_vect list and crvs list
for i, j in zip(Normal_vect, crvs):
rebars = []
#iterate over each item in sublists to create rebar doc (v = normal vector and c = curves )
for v, c in zip(i, j):
rebar = Rebar.CreateFromCurves(doc, RebarStyle.Standard, bar_type, None, None, host, v, c, RebarHookOrientation.Left, RebarHookOrientation.Right, True, False)
rebars.append(rebar)
TransactionManager.Instance.TransactionTaskDone()
OUT = rebars
Hello,
You must add the Structure namespace to have access to the Rebar class (otherwise you must specify the Structure domain in your code Structure.Rebar.CreateFromCurves(doc, Structure.RebarStyle.Standard.....) from Autodesk.Revit.DB.Structure import *
After there must also be the .Net class import (List and / or Ilist) (really not sure)
import System
from System.Collections.Generic import List,IList
too obscure for me with my current level, that’s why I deleted the message not being sure, I didn’t want to waste your time in a direction that may not be necessary
Cordially
christian.stan
I tried your code but I get an error which saying me:
error
Avertissement:IronPythonEvaluator.EvaluateIronPythonScript l’opération a échoué.
Traceback (most recent call last):
File “”, line 35, in
Exception: The input argument “barType” of function Autodesk::Revit::Proxy::DB::Structure::RebarProxy::CreateFromCurves or one item in the collection is null at line 558 of file E:\Ship\2022_px64\Source\Rebar\RebarDBAPI\gensrc\APIRebarProxy.cpp.
Parameter name: barType
here my code:
rebar
import sys
import clr
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Structure import*
from System.Collections.Generic import IList, List
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
doc = DocumentManager.Instance.CurrentDBDocument
# dynamo curves as input
geo = IN[0]
bar_type = UnwrapElement(IN[1])
host = UnwrapElement(IN[2])
vect = IN[3]
rc = []
temp = []
for i, j in zip((0, len(geo)), (0, len(vect))):
curv = List[Curve]()
for c, v in zip(geo[i], vect[j]):
curv.Add(c.ToRevitType())
TransactionManager.Instance.EnsureInTransaction(doc)
rebar = Rebar.CreateFromCurves(doc, RebarStyle.Standard, bar_type, None, None, host, v.ToRevitType(), curv, RebarHookOrientation.Left, RebarHookOrientation.Right, True, False)
TransactionManager.Instance.TransactionTaskDone()
curv = List[Curve]()
temp.append(rebar)
rc.append(temp)
temp = []
OUT = rc
Can you please try your code in my Revit model above?
Another question: since the Structure.DB is part of Revit.DB why I should import it a second time??
you ‘‘may need’’ to install this one since it comes from bartype
during the 1st import we scan the namespaces to Autodesk.Revit.DB
during the 2nd import we add the possibility of having access to the classes of Structure more directly
But then I’m a beginner, don’t forget that
Cordially
christian.stan
@christian.stan
I already select rebar bar type from Structural Design Package!!..(Have you tried your code in my model to check if you got the same error?)
We use * to import everything from Autodesk.Revit.DB so why we call Structure.DB for a second time??
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Structure import *
I had tried to explain with my words and ‘‘understanding’’ in the previous post
someone more alert than me may take over on this aspect
cordially
christian.stan
it would be useful if the models you share were not purged, the structural families are missing (or you have copy and paste the model on a non-structural template project)