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 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)
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!
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:
else:
HostedInformation = Inpt.GetHostedInfo()
for n in HostedInformation:
HostIDs.append(n.HostID)
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()
host_ids.append(hosted_info.HostId)
OUT = host_ids