Pick New Host (Multiple instead of Single)

Good day

I want to create a Pick New Host dynamo for Railings (So that I can attach the railing to Topography)
I’ve referred to https://forum.dynamobim.com/t/pick-new-host-from-the-api/13000/12
I added the filter by category so that I pick the Railings instead of the TOP railings.
However, it only works for one railing each time instead of a whole selection of railings.
Can anyone point me to the right direction?

PickNewHost.dyn (11.0 KB)

Thank you

Hi @Potato

here an example

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

toList = lambda x : x if hasattr(x, '__iter__') else [x]

#Preparing input from dynamo to revit
railings = toList(UnwrapElement(IN[0]))
newhost = UnwrapElement(IN[1])

TransactionManager.Instance.EnsureInTransaction(doc)

for railing in railings:
	if hasattr(railing, "HostId"):
		railing.HostId = newhost.Id

TransactionManager.Instance.TransactionTaskDone()

OUT = railings
2 Likes

Haven’t been on the forum for some time
Got it working somehow
Thanks!

1 Like

HI @Potato and @c.poupin

It still runs on a single element for me…could you share your code @Potato ? I would really appreciate it !

It works for me ! but i get the same message about the list(object) has no ID

Hi,
Share a screenshot of your graph showing the structure of inputs lists

Hi @c.poupin. Thank you for your time. I didnt comment that my case was a lil bit different. I had several Railing that have to be placed on Several parts of a deck. Each Part will have a Railing. In that case the Solution that you guys discussed here, doesnt work 100 % for me. With my short Knowledge of Python, I got it work for my specific case. I have to laugh because it is a simple solution and surely there is a more elegant way to fix it. Attached the your Code with my Add. Maybe it could help someone with the same case. It will be working on the Railing for a Bridge Deck. Thank You for your Code man ! :slight_smile:

Hi @J.Rymer

try this version

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

toList = lambda x : x if hasattr(x, '__iter__') else [x]

#Preparing input from dynamo to revit
railings = toList(UnwrapElement(IN[0]))
newhosts = toList(UnwrapElement(IN[1]))

TransactionManager.Instance.EnsureInTransaction(doc)

for railing, newhost in zip(railings, newhosts):
	if hasattr(railing, "HostId"):
		railing.HostId = newhost.Id

TransactionManager.Instance.TransactionTaskDone()

OUT = railings
1 Like

It works perfectly ! I tried also with the ZIP Method. My Mistake was that I forgot also to convert the Hosts in a List with your toList Lambda Method. But the Novice i=0 … i = i+1 worked too hahahaha but of course totally Novice :-). Thanks man !