Python error getting fabricaiton part hosts

I use a very similar script to get ancillary data. However when I try modify it to get hosted information I can’t get it to read. I’m trying to read the element ID of the pipe fabrication hangers are hosted to.

The API class I’m trying to use:

The property I’m after (via Revit Lookup):

I’m not experienced enough to tell if I’m missing something simple, or if what I’m trying to do is impossible.

@L-Vettz please post your dyn and rvt files (or a link)

Here’s the script and a dropbox link to a test file.

I’m using dynamo 2.0.2

GetHostedInfoTest.dyn (6.2 KB)

The GetHostedInfo() method returns a FabricationHostedInfo object, which is not iterable (explaining the error). Instead of writing for n in HostedInformation you should just do HostIDs.append(HostedInformation.HostId)

1 Like

That was it. Thank you!

1 Like

Follow up question. Is it possible to make it output a list of elements instead of a list of element ids that are strings?

I know I can just the clockwork node Element.ByID but why not try something more advanced right?

It’s actually quite simple. You can use the GetElement() method of your document. For example:

host_id = HostedInformation.HostId
host_element = Doc.GetElement(host_id)

Simple if you know what code is yea. I’m learning all this on the fly, it’s mostly still voodoo to me. Dynamo is my introduction to coding. that also worked though, thanks again!

1 Like

I am trying to follow this to get the element host of fabrication pipe hanger.
I do not see any difference between my code and your latest screenshot. However I am still getting iteration error at line 31. I am assuming I need to change the else commands to be like the if commands are?


The logic has only been fixed in the first conditional statement, so if only 1 element is provided (i.e. Cnt == 1), it is still trying to iterate the FabricationHostedInfo object. Instead of being this:

    HostedInformation = Inpt.GetHostedInfo()
    for n in HostedInformation:

It should be this:

    HostedInformation = Inpt.GetHostedInfo()

Also note that the property name is case sensitive (HostId instead of HostID), so this should be fixed on line 28 as well.

I had thought the else section would have to kinda match the if section. The case of the name totally slipped by me.

Here is a trimmed down version of the above as well (none of the imports are required and nothing has to be wrapped in a transaction as the document is not being modified).

input = UnwrapElement(IN[0])
host_ids = []

# Make input a list if it is not already
if not hasattr(input, '__iter__'):
	input = [input]

for e in input:
	hosted_info = e.GetHostedInfo()

OUT = host_ids

Thanks, that really cleans it up, and no need for for a list.count node since it is not iterating.