Get Host Family Instance (From Linked File)

I was wondering what the best method would be to get an element’s host, say in the instance of a face based family in the active document hosted onto something like a door from a linked revit model? I am aware of some nodes that provide element.host and I’ve tried using the doc.GetElement(“hostid”) in python but in the case where the host is in a linked file, it only returns the revit link instance and not the linked element. Any ideas how to achieve this?

Hi @RVT

Are you using the latest clockwork version? Looks good to me:

Hi @Kulkul, in your case you are querying the host of elements living in a linked document. I am asking to query an element in the ACTIVE document that is hosted onto something like a door living in a linked document. How do i get the host of an element i place if the HOST element is a linked file.

Hello, did you solved the question? I have the same problem. Thank you.

Hello @Kulkul,

Is there any solution for this problem? I am facing the same issue, I need to get the host of an element living in the active document where its host is an element in a linked revit model! is this open in Revit API?

Could you show us your complete graph with all the errors and previews expanded.

Thank you for the fast reply,

Actually I am writing a python code outside of dynamo. I searched the web and I didn’t find any example on how we can get the host of an element if it is in a linked model.

By using the method Element.Host it will get a RevitLinkInstance. What I want to do is to get the Id of the element in the linked revit model.

See below image of an electrical fixture living in the active document which is hosted on a wall living in a linked model… The parameter “Host” is giving the link model not the element.


Is there a direct link between the element and its host if the host is living in a linked revit file?

Thank you

hello,
try this

def getHostLink(elem):
	hostRvt = elem.Host
	hostfaceref = elem.HostFace 
	linkdoc = hostRvt.GetLinkDocument()
	hostelem = linkdoc.GetElement(hostfaceref.LinkedElementId)
	return hostelem

Hi Cyril,

First, thanks for your Python code, it worked on my side.

Secondly, would you be able to extend this code so we could select more then 1 model element at a time? This is obviously a noob question, I know nothing about Python, tried to look into ading a loop to your code, but could not find the correct syntax.

Thanks,

Maxime

Hello @msanschagrin

a function is a callable you can call it as many times as you want

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

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

toList = lambda x : x if hasattr(x, '__iter__') else [x]
lstelems = toList(UnwrapElement(IN[0]))

def getHostLink(elem):
	hostRvt = elem.Host
	hostfaceref = elem.HostFace 
	if isinstance(hostRvt, RevitLinkInstance):
		linkdoc = hostRvt.GetLinkDocument()
		hostelem = linkdoc.GetElement(hostfaceref.LinkedElementId)
		return hostelem
	else:
		return 	hostRvt
	
lsthost = []
for elem in lstelems:
	host = getHostLink(elem)
	lsthost.append(host)
	
OUT = lsthost	

Screenshot_1

Note: Remember to use the @ (example @c.poupin) so that the recipient receives a notification on the forum :wink:

4 Likes

Hello @c.poupin :wink:

A HUGE thank you, this works perfectly! I will make sure to take a look at your code when I have more free time.

Thanks again, hope this helps others too!

1 Like

CAN I DO THIS IN c# ?.

thank you so much can you help me to make script show the name of host link just name of link for multiple elements

here @BIMZN9KM

is an example

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

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

toList = lambda x : x if hasattr(x, '__iter__') else [x]
lstelems = toList(UnwrapElement(IN[0]))
	
OUT = [[x, x.Host.Name if isinstance(x.Host, RevitLinkInstance) else None] for x in lstelems]
1 Like