Copying Rebars & Rebar container to multiple elements

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 regarding the same issue, but I was unable to extract the the desired parameter All Elements of Category as I mentioned here, so do you think this script is desired in my case, if not which steps should I follow to achieve my desires

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

rebar_shaft.rvt (2.3 MB)

final_shaft_rebar.dyn (37.7 KB)

@Einar_Raknes script
Rebar.Copy.dyn (17.4 KB)

Thanks.

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


Cordially
christian.stan

1 Like

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

1 Like

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.



cordially
christian.stan

1 Like

Hi @christian.stan

Thanks for your example

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

Thanks.

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?

revit boiler plate code +

from Autodesk.Revit.DB.Structure import *

rebar_cont=UnwrapElement(IN[0])

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

Cordially
christian.stan

1 Like

@christian.stan

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

Thanks.

1 Like

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

#######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

Cordially
christian.stan

1 Like

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

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.

I opened your .rvt file and your containers are empty


Cordially
christian.stan

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

I’ll check it

Thanks

@christian.stan

Be kind to check this new file…normally it works

rebar_shaft.rvt (3.4 MB)

Thanks.

Always nothing,


I’m skipping my turn

Have a good day
Cordially
christian.stan

@christian.stan

It’s Stange!!?? :thinking:

You should run the attached script “final_shaft_rebar”…You executed it and nothing happens?

Thanks.

No, I need to install packages

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

Cordially
christian.stan

1 Like

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.

1 Like

@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?? :roll_eyes:
duplicated nodes

Please check below the corrected files that should work

updated_Shaf2.rvt (3.4 MB)

updated_shaft_rebar.dyn (37.7 KB)

sorry once again for the inconvenience.

@REDO10,

CopyContainers

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
4 Likes

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

Cordially
christian.stan

1 Like

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

Thanks for all.

1 Like