Pick new host rebar

comments to your script:

  • U can only assign one host element to a rebar element
  • the second for loop (the inner one) is not necessary as it only changes the hostelement to first one of ur input list and overwrites it with the next one. So every rebar would have the last Element in the list as HostElement
  • u dont need to do list.append for setting a new host. This was only necesary in my example for storing the actual HostId’s in a list.

For setting new Host element to multiple rebars I made this routine, which will only work for assigning a single host element to multiple rebar elements :

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

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.Elements)

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

rebarElements = UnwrapElement(IN[0])
hostElement = UnwrapElement(IN[1])

if IN[2]==True:
	for rebarElement in rebarElements:
		rebarElement.SetHostId(doc,hostElement.Id)
	
	OUT = (IN[2],rebarElements,hostElement)
else:
	OUT = (IN[2],"","")
	
TransactionManager.Instance.TransactionTaskDone()

If u want to assign multiple rebar elements to multiple rebar elements u will have to work with proper list structure or doing it with the script above step by step for each host element.