Rehost multiple elements using API

Hi Everyone,

python noob here; got stuck on making this code to work on multiple selected elements, the goal from this script is to rehost selected elements with a new host element.

import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument

doc = DocumentManager.Instance.CurrentDBDocument

railing = UnwrapElement(IN[0])
newhost = UnwrapElement(IN[1])

elements =[]

for a in railing:
    
   elements.append(a.Id)
   

TransactionManager.Instance.EnsureInTransaction(doc)

hostId = newhost.Id
railing.HostId = hostId



TransactionManager.Instance.TransactionTaskDone()

OUT = railing
OUT = 0

thanks in advance

Ho @NourAlDeen.Mustafa and welcome

Your input list seems empty, what type of element do you want to re-host?

Please take time to read the forum rules (How to get help on the Dynamo forums ) and the community guidelines (https://forum.dynamobim.com/faq )

1 Like