is it still not doable? what if i only need section box to it which cannot do in UI
Hi,
you can use Selection.SetReferences()
there is an example here
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)
try this version
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)
Tested on Revit 2024 and 2026
Can you share a simple RVT file with which the process fails (as a linked file) ?
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.
"""
lnk_instance = next((link for link in FilteredElementCollector(doc).OfClass(RevitLinkInstance)\\
if link.GetLinkDocument().GetHashCode() == lnk_doc.GetHashCode()), None)
"""
lnk_instance = UnwrapElement(IN\[1\])
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




