# How to create Rebar From Curves using Revit API and Python

**URL:** <https://forum.dynamobim.com/t/how-to-create-rebar-from-curves-using-revit-api-and-python/88348>\
**Category:** Revit\
**Tags:** python\
**Created:** [April 8, 2023, 10:06pm UTC](https://forum.dynamobim.com/t/how-to-create-rebar-from-curves-using-revit-api-and-python/88348 "2023-04-08T22:06:54Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![REDO10](https://avatars.discourse-cdn.com/v4/letter/r/7cd45c/32.png) [@REDO10](https://forum.dynamobim.com/u/REDO10)\
**Post date:** [April 8, 2023, 10:06pm UTC](https://forum.dynamobim.com/t/how-to-create-rebar-from-curves-using-revit-api-and-python/88348/1 "2023-04-08T22:06:54Z")

</div>

Hi everybody,

I’m using the Revit API method to create rebar free form curve as indicated [here](https://www.revitapidocs.com/2022/b020c9d5-6026-b9fa-7e23-f6a7ec2cede3.htm), 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:

 ![fer_radier_2023-04-08_10-56-28](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/7/b/7b049a9eb8991caab8aa47fed815f5ea8496a3a4.png)

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**
>
> ```auto
> 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
> 
> ```

Thanks.

---

<div class="post-metadata">

**Author:** ![REDO10](https://avatars.discourse-cdn.com/v4/letter/r/7cd45c/32.png) [@REDO10](https://forum.dynamobim.com/u/REDO10)\
**Post date:** [April 9, 2023, 11:00pm UTC](https://forum.dynamobim.com/t/how-to-create-rebar-from-curves-using-revit-api-and-python/88348/3 "2023-04-09T23:00:01Z")

</div>

@christian.stan

I received your reply in my email but I can’t see it in the forum??

---

<div class="post-metadata">

**Author:** ![REDO10](https://avatars.discourse-cdn.com/v4/letter/r/7cd45c/32.png) [@REDO10](https://forum.dynamobim.com/u/REDO10)\
**Post date:** [April 9, 2023, 11:58pm UTC](https://forum.dynamobim.com/t/how-to-create-rebar-from-curves-using-revit-api-and-python/88348/4 "2023-04-09T23:58:09Z")

</div>

@c.poupin

I tried something using zip function but I dont know if the iteration over curves and vectors outcome, because I get an error message:  
 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/7/4/74e5e3e97069c9f68cfb1b47f1e264294944c937.png)

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**
>
> ```auto
> 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
> 
> ```

[fer\_radier.dyn](https://forum.dynamobim.com/uploads/short-url/os3E0P0lrbS5Nu6aqCiijBwpRN.dyn) (22.5 KB)  
[Raft\_rebar.rvt](https://forum.dynamobim.com/uploads/short-url/7bz3rU331IZo3xzRNXL1H99OsYe.rvt) (2.2 MB)  
[Radier\_chateau\_eau\_1000.rfa](https://forum.dynamobim.com/uploads/short-url/qa82gw3gAtdpGsiq8DQMC6Tnndh.rfa) (440 KB)

Thanks.

---

<div class="post-metadata">

**Author:** ![christian.stan](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/christian.stan/32/166296_2.png) [@christian.stan](https://forum.dynamobim.com/u/christian.stan)\
**Post date:** [April 10, 2023, 7:34am UTC](https://forum.dynamobim.com/t/how-to-create-rebar-from-curves-using-revit-api-and-python/88348/5 "2023-04-10T07:34:06Z")

</div>

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)

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/6/7/673f7f05233c785a7b0caf20a2abd3e0692332b1.png)

```auto
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

---

<div class="post-metadata">

**Author:** ![christian.stan](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/christian.stan/32/166296_2.png) [@christian.stan](https://forum.dynamobim.com/u/christian.stan)\
**Post date:** [April 10, 2023, 12:01pm UTC](https://forum.dynamobim.com/t/how-to-create-rebar-from-curves-using-revit-api-and-python/88348/6 "2023-04-10T12:01:31Z")

</div>

Hello, with great difficulty I succeeded, (but hey I think there must be much faster)

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/c/d/cd9892481fc602087fb13e1362107e8e6137e323.png)

```auto
import clr
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import*
from Autodesk.Revit.DB.Structure 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)

import System 
from System.Collections.Generic import List

doc = DocumentManager.Instance.CurrentDBDocument

curv_dyn=IN[0]
reb_typ=UnwrapElement(IN[1])
col=UnwrapElement(IN[2])
vec_dyn=IN[3]

rc=[]
temp=[]
#vec=vec_dyn.ToRevitType()

for k,l in zip(range(0, len(curv_dyn)),range(0, len(vec_dyn))):
    curv_l=List[Curve]()
    for i,j in zip(curv_dyn[k],vec_dyn[l]):
        curv_l.Add(i.ToRevitType())
        TransactionManager.Instance.EnsureInTransaction(doc)
        r=Rebar.CreateFromCurves(doc,RebarStyle.Standard,reb_typ,None,None,col,j.ToRevitType(),curv_l,RebarHookOrientation.Right,RebarHookOrientation.Left,True,False)
        TransactionManager.Instance.TransactionTaskDone()
        curv_l=List[Curve]()
        temp.append(r)
    rc.append(temp)
    temp=[]

OUT=rc

```

cordially  
christian.stan

---

<div class="post-metadata">

**Author:** ![REDO10](https://avatars.discourse-cdn.com/v4/letter/r/7cd45c/32.png) [@REDO10](https://forum.dynamobim.com/u/REDO10)\
**Post date:** [April 10, 2023, 1:11pm UTC](https://forum.dynamobim.com/t/how-to-create-rebar-from-curves-using-revit-api-and-python/88348/7 "2023-04-10T13:11:33Z")

</div>

Hi @christian.stan

Thanks for your Job

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**
>
> ```auto
> 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??

Thanks.

---

<div class="post-metadata">

**Author:** ![christian.stan](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/christian.stan/32/166296_2.png) [@christian.stan](https://forum.dynamobim.com/u/christian.stan)\
**Post date:** [April 10, 2023, 1:56pm UTC](https://forum.dynamobim.com/t/how-to-create-rebar-from-curves-using-revit-api-and-python/88348/8 "2023-04-10T13:56:41Z")

</div>

I used a custom node from Mr. Fudala  
 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/b/d/bdc38fa8a58d95d4e29a14712cb96cadbe334d10.png)

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

---

<div class="post-metadata">

**Author:** ![REDO10](https://avatars.discourse-cdn.com/v4/letter/r/7cd45c/32.png) [@REDO10](https://forum.dynamobim.com/u/REDO10)\
**Post date:** [April 10, 2023, 2:48pm UTC](https://forum.dynamobim.com/t/how-to-create-rebar-from-curves-using-revit-api-and-python/88348/9 "2023-04-10T14:48:47Z")

</div>

@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??

Thanks

---

<div class="post-metadata">

**Author:** ![christian.stan](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/christian.stan/32/166296_2.png) [@christian.stan](https://forum.dynamobim.com/u/christian.stan)\
**Post date:** [April 10, 2023, 3:29pm UTC](https://forum.dynamobim.com/t/how-to-create-rebar-from-curves-using-revit-api-and-python/88348/10 "2023-04-10T15:29:41Z")

</div>

you have forgot range in first for

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/f/b/fb2fea9a2c7b6f8f3c8a73b4c13543cdae7871e0.png)

edit: you have forgot too` import System`

edit:2  
and concerning:

```auto
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

---

<div class="post-metadata">

**Author:** ![c.poupin](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/c.poupin/32/89152_2.png) [@c.poupin](https://forum.dynamobim.com/u/c.poupin)\
**Post date:** [April 10, 2023, 5:29pm UTC](https://forum.dynamobim.com/t/how-to-create-rebar-from-curves-using-revit-api-and-python/88348/11 "2023-04-10T17:29:24Z")

</div>

> [@REDO10](#):
>
> We use \* to import everything from **Autodesk.Revit.DB** so why we call Structure.DB for a second time??

because namespaces are different, need to import both (although there is an inheritance system between)

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/8/f/8f3812758ef0d74acc49eb48806d1a0a903cfa34.png)

> [@REDO10](#):
>
> 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?)

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)

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/4/6/4694d32558f98faf55a7a6f83e443de3c9c79f51.png)

---

<div class="post-metadata">

**Author:** ![REDO10](https://avatars.discourse-cdn.com/v4/letter/r/7cd45c/32.png) [@REDO10](https://forum.dynamobim.com/u/REDO10)\
**Post date:** [April 13, 2023, 2:17pm UTC](https://forum.dynamobim.com/t/how-to-create-rebar-from-curves-using-revit-api-and-python/88348/12 "2023-04-13T14:17:58Z")

</div>

@c.poupin

Thanks for your explanation about the Revit API namespaces and their uses domain!

I corrected my script and the rebars are created correctely.  
Now, I want to group the rebars with the sames length in a set, so how to do that?

 ![rebar_set](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/2/b/2b76b3c8d2f980ee852387cd406ed15b1f4be4dd.png)

Thanks.

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [April 13, 2023, 2:39pm UTC](https://forum.dynamobim.com/t/how-to-create-rebar-from-curves-using-revit-api-and-python/88348/13 "2023-04-13T14:39:35Z")

</div>

> [@REDO10](#):
>
> Now, I want to group the rebars with the sames length in a set, so how to do that?

Please start a new topic as that is a different issue.
