Pick New Host from the API?

Hello, everybody!
I looked through the API docs and I couldn’t find anything, but I might still be missing something here.
Is there an analog to Pick New Host in the API?


Did you ever find an answer to this? I’m looking for the same question’s answer.

The property HostId can be retrieved and set, so this Python script should do it:

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])

TransactionManager.Instance.EnsureInTransaction(doc)

hostId = newhost.Id
railing.HostId = hostId

TransactionManager.Instance.TransactionTaskDone()

OUT = railing
10 Likes

I totally forgot I made this topic.
I eventually found the HostId thing and it turned out to be straightforward. The thing I was working on though took another way so I never used it.
The sample script from @awilliams is working and it’s great.

2 Likes

5 posts were split to a new topic: Pick new host lighting fixture

@Mark.Ackerley moved to new topic here

2 Likes

This looks like something I need to use but for a Double Tee Framing member. I notice this is for a railing. Not too familiar with Python, what would I need to change for that.

Has the python code changed since this original script was written?

This is what I have but I keep getting errors about “Top Rail” having no ID on the second selected railing and it will not change its host for some reason. PS I only have 2 selected railing elements, but it does report as 4 ids in the dynamo selection script box…

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

railings = UnwrapElement(IN[0])
newHost = UnwrapElement(IN[1])

TransactionManager.Instance.EnsureInTransaction(doc)

for i in railings:
** i.HostId = newHost.Id**
TransactionManager.Instance.TransactionTaskDone()

OUT = railings

image

image

Hi @Jaysyn.quarry !
Did you find any solution ? I have the same problem right now