# Highlight linked element

**URL:** <https://forum.dynamobim.com/t/highlight-linked-element/112606>\
**Category:** Revit\
**Tags:** python, dynamo\
**Created:** [October 7, 2025, 5:31pm UTC](https://forum.dynamobim.com/t/highlight-linked-element/112606 "2025-10-07T17:31:44Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![ning.zhouHNQLJ](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/ning.zhouhnqlj/32/201653_2.png) [@ning.zhouHNQLJ](https://forum.dynamobim.com/u/ning.zhouHNQLJ)\
**Post date:** [October 7, 2025, 5:31pm UTC](https://forum.dynamobim.com/t/highlight-linked-element/112606/1 "2025-10-07T17:31:44Z")

</div>

is it still not doable? what if i only need section box to it which cannot do in UI

---

<div class="post-metadata">

**Author:** ![c.poupin](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/c.poupin/32/89152_2.png) [@c.poupin](https://forum.dynamobim.com/u/c.poupin)\
**Post date:** [October 7, 2025, 6:48pm UTC](https://forum.dynamobim.com/t/highlight-linked-element/112606/2 "2025-10-07T18:48:37Z")

</div>

Hi,

you can use `Selection.SetReferences()`

> **[Help](https://help.autodesk.com/view/RVT/2026/ENU/?guid=813a9d31-bc4f-1ebc-9a7b-69a2a99d22ac)**

there is an example here

> [@Manual selection or working with preselected elements in a linked model](https://forum.dynamobim.com/t/manual-selection-or-working-with-preselected-elements-in-a-linked-model/112527/20):
>
> hi, here is an example import clr import sys import System #import net library from System import Array from System.Collections.Generic import List, IList, Dictionary, HashSet #import Revit API clr.AddReference('RevitAPI') import Autodesk from Autodesk.Revit.DB import \* import Autodesk.Revit.DB as DB #import Revit APIUI namespace clr.AddReference('RevitAPIUI') import Autodesk.Revit.UI as RUI from Autodesk.Revit.UI.Selection import \* #import transactionManager and DocumentManager (Revi…

---

<div class="post-metadata">

**Author:** ![ning.zhouHNQLJ](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/ning.zhouhnqlj/32/201653_2.png) [@ning.zhouHNQLJ](https://forum.dynamobim.com/u/ning.zhouHNQLJ)\
**Post date:** [October 7, 2025, 8:27pm UTC](https://forum.dynamobim.com/t/highlight-linked-element/112606/3 "2025-10-07T20:27:18Z")

</div>

cool! thanks c.poupin, i managed to get linked element but how to convert that linked element to reference so it can be used in Selection.SetReferences()

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/5/3/535e89e255c919880865a6d620b5c26269cf4180.png)

---

<div class="post-metadata">

**Author:** ![ning.zhouHNQLJ](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/ning.zhouhnqlj/32/201653_2.png) [@ning.zhouHNQLJ](https://forum.dynamobim.com/u/ning.zhouHNQLJ)\
**Post date:** [October 8, 2025, 4:28pm UTC](https://forum.dynamobim.com/t/highlight-linked-element/112606/4 "2025-10-08T16:28:02Z")

</div>

tried below Python code but not working:

linkElems = UnwrapElement(IN[0])  
linkInstance = UnwrapElement(IN[1])  
linkReferences = List[Reference]([Reference(linkElem).CreateLinkReference(linkInstance) for linkElem in linkElems])  
uidoc.Selection.SetReferences(linkReferences)

---

<div class="post-metadata">

**Author:** ![c.poupin](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/c.poupin/32/89152_2.png) [@c.poupin](https://forum.dynamobim.com/u/c.poupin)\
**Post date:** [October 8, 2025, 6:09pm UTC](https://forum.dynamobim.com/t/highlight-linked-element/112606/5 "2025-10-08T18:09:57Z")

</div>

try this version

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/b/6/b6199d02420706409fbb640f5184f253bbd9079d.png)

```python
import clr
import sys
import System
#import net library
from System import Array
from System.Collections.Generic import List, IList, Dictionary, HashSet

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

#import Revit APIUI namespace
clr.AddReference('RevitAPIUI')
import Autodesk.Revit.UI as RUI
from Autodesk.Revit.UI.Selection import *

#import transactionManager and DocumentManager (RevitServices is specific to Dynamo)
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
uidoc = uiapp.ActiveUIDocument
app = uiapp.Application

    
def select_link_elems(lstElem):
    lst_refs = List[Reference]()
    for e in lstElem:
        lnk_doc = e.Document
        lnk_instance = next(( link for link in FilteredElementCollector(doc).OfClass(RevitLinkInstance)\
                            if link.GetLinkDocument().GetHashCode() == lnk_doc.GetHashCode()), None)
        if lnk_instance:
            ref = Reference(e).CreateLinkReference(lnk_instance)
            lst_refs.Add(ref)
            
    uidoc.Selection.SetReferences(lst_refs)
    return lstElem
    
def toList(x):
    if isinstance(x, (list, dict)) or \
            (hasattr(x, "GetType") and x.GetType().GetInterface("ICollection") is not None):
        return x
    else : return [x]
# OR 
toList = lambda x : x if hasattr(x, " __iter__") and not isinstance(x, (str, System.String)) else [x]

#Preparing input from dynamo to revit
lstelems = toList(UnwrapElement(IN[0]))
OUT = select_link_elems(lstelems)

```

---

<div class="post-metadata">

**Author:** ![ning.zhouHNQLJ](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/ning.zhouhnqlj/32/201653_2.png) [@ning.zhouHNQLJ](https://forum.dynamobim.com/u/ning.zhouHNQLJ)\
**Post date:** [October 8, 2025, 9:12pm UTC](https://forum.dynamobim.com/t/highlight-linked-element/112606/6 "2025-10-08T21:12:26Z")

</div>

no luck, i assume it’s version issue, i’m using Revit 2024, which version are you using? by the way, linked elements highlighted because of selecting which is not desired, or after running script which is desired.

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/b/3/b34276721c3af317066bd2b64c641097115530b8.png)

---

<div class="post-metadata">

**Author:** ![c.poupin](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/c.poupin/32/89152_2.png) [@c.poupin](https://forum.dynamobim.com/u/c.poupin)\
**Post date:** [October 8, 2025, 9:23pm UTC](https://forum.dynamobim.com/t/highlight-linked-element/112606/7 "2025-10-08T21:23:43Z")

</div>

Tested on Revit 2024 and 2026

Can you share a simple RVT file with which the process fails (as a linked file) ?

---

<div class="post-metadata">

**Author:** ![ning.zhouHNQLJ](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/ning.zhouhnqlj/32/201653_2.png) [@ning.zhouHNQLJ](https://forum.dynamobim.com/u/ning.zhouHNQLJ)\
**Post date:** [October 8, 2025, 9:43pm UTC](https://forum.dynamobim.com/t/highlight-linked-element/112606/8 "2025-10-08T21:43:06Z")

</div>

tested w/ new RVTs, works great! i need to take another look at project RVT and script, very appreciated for your help c.poupin!

edit: found a bug in my script, works great now w/ minor change, thanks again for your help c.poupin.

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/5/7/5784768dd8cad44118c07084b2a0bdbb1de64e3f.png)

```
    """
    lnk_instance = next((link for link in FilteredElementCollector(doc).OfClass(RevitLinkInstance)\\
                        if link.GetLinkDocument().GetHashCode() == lnk_doc.GetHashCode()), None)
    """
    lnk_instance = UnwrapElement(IN\[1\])

```

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/b/b/bb866c9a94b5e09ee2c6b68b1a31c89f7df7f8dd.png)

---

<div class="post-metadata">

**Author:** ![ning.zhouHNQLJ](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/ning.zhouhnqlj/32/201653_2.png) [@ning.zhouHNQLJ](https://forum.dynamobim.com/u/ning.zhouHNQLJ)\
**Post date:** [October 9, 2025, 4:03pm UTC](https://forum.dynamobim.com/t/highlight-linked-element/112606/9 "2025-10-09T16:03:18Z")

</div>

is it doable to have both host elements and linked elements highlighted, currently i have to do it separated, kind of combining below 2 lines together

for host elements → uidoc.Selection.SetElementIds()

for linked elements → uidoc.Selection.SetReferences()

edit: did a test, cannot use both, means host elements also need to be converted to references and only use uidoc.Selection.SetReferences() i believe

edit: works OK now
