# Copying Rebars & Rebar container to multiple elements

**URL:** <https://forum.dynamobim.com/t/copying-rebars-rebar-container-to-multiple-elements/92588>\
**Category:** Uncategorized\
**Created:** [August 4, 2023, 7:09pm UTC](https://forum.dynamobim.com/t/copying-rebars-rebar-container-to-multiple-elements/92588 "2023-08-04T19:09:22Z")\
**Posts on this page:** 20\
**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:** [August 4, 2023, 7:09pm UTC](https://forum.dynamobim.com/t/copying-rebars-rebar-container-to-multiple-elements/92588/1 "2023-08-04T19:09:22Z")

</div>

Hi everyone, @c.poupin @Organon

To copy Rebars and Rebar container from a shaft to others shown in the image below, I thought to follow steps in @Einar_Raknes script posted [here](https://forum.dynamobim.com/t/copy-rebar-from-one-element-to-another/7431/13) regarding the same issue, but I was unable to extract the the desired parameter `All Elements of Category` as I mentioned [here](https://forum.dynamobim.com/t/get-all-elements-of-category-using-api/92418/10), so do you think this script is desired in my case, if not which steps should I follow to achieve my desires

 ![Shaft](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/3/7/376005b24cb268aca89d2c6e8abbfb0c2b38d076.png)

These are my references, be kind engough to check them for me

[rebar\_shaft.rvt](https://forum.dynamobim.com/uploads/short-url/ytu6FNG7QSrF8Qtg9rBt2JJPOGh.rvt) (2.3 MB)

[final\_shaft\_rebar.dyn](https://forum.dynamobim.com/uploads/short-url/kTD1Uzv6M4JD4pU73zxndosdJjM.dyn) (37.7 KB)

@Einar_Raknes script  
[Rebar.Copy.dyn](https://forum.dynamobim.com/uploads/short-url/iVeCsCTRBOeCnXMlkEAVpQm27AP.dyn) (17.4 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:** [August 4, 2023, 7:48pm UTC](https://forum.dynamobim.com/t/copying-rebars-rebar-container-to-multiple-elements/92588/2 "2023-08-04T19:48:52Z")

</div>

Hello, as the rebars are hosts of the concrete element if you copy the element the rebar sets follow.  
You will probably have to assign to your elements already present then delete the corresponding host elts

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/6/2/62cf10bf28dc8b4871b5af977bb7cad92f7c26a3.png)  
 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/7/8/7828dc4d0fdee4386046a824036422db39c4117f.png)

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:** [August 4, 2023, 9:10pm UTC](https://forum.dynamobim.com/t/copying-rebars-rebar-container-to-multiple-elements/92588/3 "2023-08-04T21:10:28Z")

</div>

Thanks for your reply @christian.stan

I prefere use API, and I dont know if your approach can be done with API and if containers can follow the copied elements.

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:** [August 5, 2023, 9:38am UTC](https://forum.dynamobim.com/t/copying-rebars-rebar-container-to-multiple-elements/92588/4 "2023-08-05T09:38:08Z")

</div>

Hello, I tried too  
with generic model (the containers follow), so in your example copy element after having scrapped it then make your alternative rotations (already treated later)  
(why do you want to make your file heavier if your distribution is the same on levels)

If you only want to use the API here (ClockWork package person node will always be better optimized), than a lame version from me.

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/9/e/9e742cc755f25fb92def64f64cb9075f1f1ce2df.png)  
 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/3/6/364c1a508ba00c54b1bf561165c27dec652a61fa.png)  
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:** [August 5, 2023, 12:47pm UTC](https://forum.dynamobim.com/t/copying-rebars-rebar-container-to-multiple-elements/92588/5 "2023-08-05T12:47:07Z")

</div>

Hi @christian.stan

Thanks for your example

> [@christian.stan](#):
>
> (why do you want to make your file heavier if your distribution is the same on levels)

I dont understand what you mean, why my file is heavy?

I tried your example, but elements are not copied as shown in the graph below

 ![copy_elements_christian_2023-08-05_01-46-36](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/9/9/99f8aae6a765858600528fc97115a93f67bc269e.png)

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:** [August 5, 2023, 2:51pm UTC](https://forum.dynamobim.com/t/copying-rebars-rebar-container-to-multiple-elements/92588/6 "2023-08-05T14:51:11Z")

</div>

When is it when you copy this element under revit manually (without dynamo) do your steels follow?

edit:  
Are your containersRebar hosts to your element?

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

[revit boiler plate code](https://dynamopythonprimer.gitbook.io/dynamo-python-primer/getting-started/boilerplate-setup-code) +

```auto
from Autodesk.Revit.DB.Structure import *

rebar_cont=UnwrapElement(IN[0])

OUT = [r.GetHostId().IntegerValue for r in rebar_cont]

```

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:** [August 5, 2023, 5:40pm UTC](https://forum.dynamobim.com/t/copying-rebars-rebar-container-to-multiple-elements/92588/7 "2023-08-05T17:40:19Z")

</div>

@christian.stan

> [@christian.stan](#):
>
> When is it when you copy this element under revit manually (without dynamo) do your steels follow?

When copying elements manualy, rebars not follows and I get an error message saying “rebar is placed completely outside of its host”

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

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:** [August 5, 2023, 9:00pm UTC](https://forum.dynamobim.com/t/copying-rebars-rebar-container-to-multiple-elements/92588/8 "2023-08-05T21:00:13Z")

</div>

I think I was confusing Set and Container  
It’s a little less hazy now but not super clear  
here are some research done on the API  
There is a host for the container

```auto
#######OK NOW YOU CAN CODE########
from Autodesk.Revit.DB.Structure import *

rebar_sets=UnwrapElement(IN[0])
elt_host=UnwrapElement(IN[1])

TransactionManager.Instance.EnsureInTransaction(doc)
#Create the container Type
cont_type_balcon=RebarContainerType.GetOrCreateRebarContainerType(doc,'Container du balcon 03')
#Create the container
cont_balcon=RebarContainer.Create(doc,elt_host,cont_type_balcon)
#Append the set for the container
[cont_balcon.AppendItemFromRebar(r) for r in rebar_sets]
TransactionManager.Instance.TransactionTaskDone()

OUT = cont_type_balcon,cont_balcon,{'Host Element':cont_balcon.GetHostId()},[cont_balcon.GetItem(0),cont_balcon.GetItem(1)]

```

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/6/8/686a5ccf8aba33a0f91bad9c0aa322cbaa82ea43.png)  
 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/2/a/2a3b22e7d18a1974fc30ea15167284bb6ec87f66.png)

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:** [August 6, 2023, 9:47am UTC](https://forum.dynamobim.com/t/copying-rebars-rebar-container-to-multiple-elements/92588/9 "2023-08-06T09:47:31Z")

</div>

Hi @christian.stan,

Thanks for your last reply

My problem is not related to creation of rebar containers!! …my containers are already created and filled by their corresponding rebar (Have you run my script above to see how things go?)

As I said above, I want to follow @Einar_Raknes sample which seems to me is a similar case and it’s concept is: getting the **rebars Ids** based on their **category** from the source element and include them in the target host using " **SetHostId**  **Method**" as is demonstrated in the last part of his script below  
 ![rebar_target](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/1/a/1aab883d7bd5bfe27190d235b995276e8ce96e3d.png)

but the problem in my case rebars are associated to their containers and I can’t copy them according to the Einar script without extracting them from their containers and I dont know how to do that??

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:** [August 6, 2023, 11:57am UTC](https://forum.dynamobim.com/t/copying-rebars-rebar-container-to-multiple-elements/92588/10 "2023-08-06T11:57:02Z")

</div>

I opened your .rvt file and your containers are empty

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/5/c/5cb0387ba0a617c8a49bea59f398e28c9304c25c.png)  
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:** [August 6, 2023, 12:13pm UTC](https://forum.dynamobim.com/t/copying-rebars-rebar-container-to-multiple-elements/92588/11 "2023-08-06T12:13:16Z")

</div>

@christian.stan  
Rebars are not drawn in the model?

I’ll check it

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:** [August 6, 2023, 2:23pm UTC](https://forum.dynamobim.com/t/copying-rebars-rebar-container-to-multiple-elements/92588/12 "2023-08-06T14:23:06Z")

</div>

@christian.stan

Be kind to check this new file…normally it works

[rebar\_shaft.rvt](https://forum.dynamobim.com/uploads/short-url/g71ynE4VKSPx1hXiZ829lCSMJvt.rvt) (3.4 MB)

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:** [August 6, 2023, 2:52pm UTC](https://forum.dynamobim.com/t/copying-rebars-rebar-container-to-multiple-elements/92588/13 "2023-08-06T14:52:15Z")

</div>

Always nothing,

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/c/6/c61a4b271b8adf2e5e1264b34a17774d42e2eb3c.png)  
I’m skipping my turn

Have a good day  
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:** [August 6, 2023, 3:09pm UTC](https://forum.dynamobim.com/t/copying-rebars-rebar-container-to-multiple-elements/92588/14 "2023-08-06T15:09:05Z")

</div>

@christian.stan

It’s Stange!!?? 🤔

You should run the attached script “ **final\_shaft\_rebar** ”…You executed it and nothing happens?

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:** [August 6, 2023, 3:44pm UTC](https://forum.dynamobim.com/t/copying-rebars-rebar-container-to-multiple-elements/92588/15 "2023-08-06T15:44:15Z")

</div>

No, I need to install packages

(why not send a file with a lift already scrapped)

Cordially  
christian.stan

---

<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:** [August 6, 2023, 3:49pm UTC](https://forum.dynamobim.com/t/copying-rebars-rebar-container-to-multiple-elements/92588/16 "2023-08-06T15:49:47Z")

</div>

To rephrase what @christian.stan indicated: if your problem is with copying rebar from one mass to another, generate one of each rebar class (rebar container or rebar) with a very simple design, and share that file to build your code against that. Once that is solved you can assemble the various parts and pieces into the full graph by moving the custom nodes to scale (yes, your work should be packed into packages custom nodes, on the package manager or elsewhere) into sequence to create and copy the rebar in one graph.

---

<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:** [August 6, 2023, 5:31pm UTC](https://forum.dynamobim.com/t/copying-rebars-rebar-container-to-multiple-elements/92588/17 "2023-08-06T17:31:37Z")

</div>

@christian.stan

Sorry for this unuseful loss of time !!

It’s strange!!..I dont know what’s happened with my revit and dyn files??  
when I opened the dyn file I found a duplicated keys of the nodes **`RebarbarType`** and **`RebarhookType`** I don’t know what this is due to?? 🙄  
 ![duplicated nodes](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/6/d/6da825652866b6ceb01aa5f64d13ea66bfc6b5f9.png)

Please check below the corrected files that should work

[updated\_Shaf2.rvt](https://forum.dynamobim.com/uploads/short-url/mSBzmsv8KPyYOetykXPzPuMndpb.rvt) (3.4 MB)

[updated\_shaft\_rebar.dyn](https://forum.dynamobim.com/uploads/short-url/bv7d4ZT6Ph2QbHHMZS9G0WtK9ia.dyn) (37.7 KB)

sorry once again for the inconvenience.

---

<div class="post-metadata">

**Author:** ![Organon](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/organon/32/161404_2.png) [@Organon](https://forum.dynamobim.com/u/Organon)\
**Post date:** [August 6, 2023, 6:13pm UTC](https://forum.dynamobim.com/t/copying-rebars-rebar-container-to-multiple-elements/92588/18 "2023-08-06T18:13:36Z")

</div>

@REDO10,

![CopyContainers](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/6/f/6fdb9e3a74970d621da8b546ac970b8961526b4b.gif)

```auto
import clr
from System.Collections.Generic import *

clr.AddReference('RevitAPI')
clr.AddReference('RevitAPIUI')
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Structure import *
from Autodesk.Revit.UI import *
from Autodesk.Revit.UI.Selection import *

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

uidoc = DocumentManager.Instance.CurrentUIDocument
doc = DocumentManager.Instance.CurrentDBDocument

# Select first element.
firstRef = uidoc.Selection.PickObject(ObjectType.Element, "Select first element.")
firstElement = doc.GetElement(firstRef)

# Get rebar containers.
first_rebarHostData = RebarHostData.GetRebarHostData(firstElement)
first_containersInHost = first_rebarHostData.GetRebarContainersInHost()
old_containerIds = List[ElementId]([c.Id for c in first_containersInHost])

# Select second element.
secondRef = uidoc.Selection.PickObject(ObjectType.Element, "Select second element.")
secondElement = doc.GetElement(secondRef)
level = doc.GetElement(secondElement.LevelId)

# Copy containers.
TransactionManager.Instance.EnsureInTransaction(doc)
translation = XYZ(0, 0, level.Elevation)
new_containerIds = ElementTransformUtils.CopyElements(doc, old_containerIds, translation)
TransactionManager.Instance.TransactionTaskDone()

new_containers = []
for containerId in new_containerIds:
    container = doc.GetElement(containerId)
    container.SetHostId(doc, secondElement.Id)
    new_containers.append(container)

OUT = new_containers

```

---

<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:** [August 6, 2023, 6:14pm UTC](https://forum.dynamobim.com/t/copying-rebars-rebar-container-to-multiple-elements/92588/19 "2023-08-06T18:14:09Z")

</div>

a file with rebars already present between level 1 and 2 that would be good to see if it comes from the version you are using

I’m not sure but maybe Mr. AndyDandy (in his custom node) used the SetAssociatedLevel Method of the LevelAssociatedData Class  
As it is a class of v2023 it smells very bad  
I don’t know if an element can be copied from one level to another level with the Element TransformUtils class (in the same level yes)

i will try tomorrow if i get a file with rebars  
edit: Thanks Mr. Organon, you fixed it

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

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:** [August 6, 2023, 7:04pm UTC](https://forum.dynamobim.com/t/copying-rebars-rebar-container-to-multiple-elements/92588/20 "2023-08-06T19:04:42Z")

</div>

Thank you very much @Organon , I knew you had the solution to my issue and I am very gratefull

Thanks for all.

[Next page](https://forum.dynamobim.com/t/copying-rebars-rebar-container-to-multiple-elements/92588.md?page=2)
