Get Tag Host Element from element in a Linked Model

I am trying to find the Door Tag host element (the door), however the elements are in a linked model. (tags are in my model)

I am using Springs.Collector.ElementsInView to collect all the Tags, it outputs IndependentTags.

I have tried to use a few different nodes from different packages but they don’t work (see picture). I think the reason they don’t work is because they look in the local model not the linked models.

Any ideas on how to get the host element?

thanks

Hi,

This is not the same topic as the quoted post. I ask here for a method to derive the host element from a linked model.

I know there is a command for it, but I do not know how to use it. (linkelementId= tag.TaggedElementId)

archilab has a node for finding the host element of the local model, wondering if anyone has adapted it for a linked model. @Konrad_K_Sobon and @Timon explain it in the following post, but with no example.
Wondering if anyone has implemented the method explained for linked models and can share their code?
http://dynamobim.org/forums/topic/host-of-tag/

Thanks

So you can get an element from the ID using the following code in the API.

docvar.GetElementId(linkedelementid)

In this code above docvar is a variable that hosts the document you are searching and elementidvar is the variable that contains the element id you are looking to gain.

For context, if you use the local document in docvar, it will get the element from the local model with that element id, but if you insert a linked model document into that variable you will get the element that has that element Id in the linked model. The code works the same for each.

If you can get the document of the linked model you can use the code mentioned above by @Ben.AR. the link he posts has much of the relevant information.

Thanks for the help, I don’t know where I am going wrong. Below is my graph and adapted code from @Konrad_K_Sobon archilab:

Hope someone can help,


#Copyright© 2015, Konrad K Sobon
# @arch_laboratory, http://archi-lab.net

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

# Import Element wrapper extension methods
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.Elements)

# Import DocumentManager and TransactionManager
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

docvar = IN[1]

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

import sys
pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
sys.path.append(pyt_path)

#The inputs to this node will be stored as a list in the IN variable.
dataEnteringNode = IN

if isinstance(IN[0], list):
	elem = [UnwrapElement(i) for i in IN[0]]
else:
	elem = [UnwrapElement(IN[0])]

def ProcessList(_func, _list):
    return map( lambda x:
    process_list(_func, x) if type(x)==list else _func(x), _list )

def GetHostElement(IndependentTag):
	#hostElemId = tag.TaggedLocalElementId
	linkelementId= IndependentTag.TaggedElementId
	element = docvar.GetElementId(linkedelementid)
	#hostElem = doc.GetElement(hostElemId)
	return element

try:
	errorReport = None
	output = ProcessList(GetHostElement, elem)
except:
	# if error accurs anywhere in the process catch it
	import traceback
	errorReport = traceback.format_exc()

#Assign your output to the OUT variable
if errorReport == None:
	OUT = output
else:
	OUT = errorReport

Check your capitalization of variable. It looks like they vary.

Also it looks like the code is not intended to work with nested lists of lists, so you could try flattening the input[0] before connecting it to the python node.

Thanks for your help

I added the flatten and fixed my variable naming and now getting a different traceback error:

[0] Traceback (most recent call last):
File “”, line 51, in
File “”, line 39, in ProcessList
File “”, line 40, in <lambda$484>
File “”, line 45, in GetHostElement
AttributeError: ‘Document’ object has no attribute ‘GetElementId’

#Copyright(c) 2015, Konrad K Sobon
# @arch_laboratory, http://archi-lab.net

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

# Import Element wrapper extension methods
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.Elements)

# Import DocumentManager and TransactionManager
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

docvar = IN[1]

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

import sys
pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
sys.path.append(pyt_path)

#The inputs to this node will be stored as a list in the IN variable.
dataEnteringNode = IN

if isinstance(IN[0], list):
	elem = [UnwrapElement(i) for i in IN[0]]
else:
	elem = [UnwrapElement(IN[0])]

def ProcessList(_func, _list):
    return map( lambda x:
    process_list(_func, x) if type(x)==list else _func(x), _list )

def GetHostElement(IndependentTag):
	#hostElemId = tag.TaggedLocalElementId
	linkedelementid= IndependentTag.TaggedElementId
	element = docvar.GetElementId(linkedelementid)
	#hostElem = doc.GetElement(hostElemId)
	return element

try:
	errorReport = None
	output = ProcessList(GetHostElement, elem)
except:
	# if error accurs anywhere in the process catch it
	import traceback
	errorReport = traceback.format_exc()

#Assign your output to the OUT variable
if errorReport == None:
	OUT = output
else:
	OUT = errorReport

Hi,

You missed a step, you need to turn the LinkedElementId into ElementId.

#Copyright(c) 2015, Konrad K Sobon
# @arch_laboratory, http://archi-lab.net

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

# Import Element wrapper extension methods
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.Elements)

# Import DocumentManager and TransactionManager
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = IN[1]

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

import sys
pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
sys.path.append(pyt_path)

#The inputs to this node will be stored as a list in the IN variable.
dataEnteringNode = IN

if isinstance(IN[0], list):
	elem = [UnwrapElement(i) for i in IN[0]]
else:
	elem = [UnwrapElement(IN[0])]

def ProcessList(_func, _list):
    return map( lambda x:
    process_list(_func, x) if type(x)==list else _func(x), _list )

def GetHostElement(IndependentTag):
	#hostElemId = tag.TaggedLocalElementId
	linkelementid= IndependentTag.TaggedElementId
	element = doc.GetElement(linkelementid.LinkedElementId)
	#hostElem = doc.GetElement(hostElemId)
	return element

try:
	errorReport = None
	output = ProcessList(GetHostElement, elem)
except:
	# if error accurs anywhere in the process catch it
	import traceback
	errorReport = traceback.format_exc()

#Assign your output to the OUT variable
if errorReport == None:
	OUT = output
else:
	OUT = errorReport

1 Like

There was also a typo in the original code.

Instead of using GetElementId, use GetElement

@Timon and @Alban_de_Chasteigner

Thank you both! I got it to work.

Hi,

I updated the Tag Get tagged Element node and it now works with tags on linked elements and linked rooms.
This could be useful for others topic viewers.
image

Thanks to Andreas Dieckmann for the part of the script with the conditional statement on the document.

2 posts were split to a new topic: Get Tag Host Element from element in many linked models

Hello @Alban_de_Chasteigner,

Great work, Any similar solution to get the host of a familyInstance instead of a tag in a Linked model?

Thank you