Hide Linked Elements in Active view

import clr

clr.AddReference(‘RevitAPI’)
from Autodesk.Revit import DB
from Autodesk.Revit.DB import FilteredElementCollector, BuiltInCategory

clr.AddReference(‘RevitAPIUI’)
from Autodesk.Revit.UI import *

clr.AddReference(‘System’)
from System.Collections.Generic import List

clr.AddReference(‘RevitNodes’)
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)

clr.AddReference(‘RevitServices’)
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
view = uidoc.ActiveView

Preparing input from dynamo to revit

linkInst = UnwrapElement(IN[0])
parameterName = “Chamber Depth”
parameterValue = (1800)/304.8

linkDoc = linkInst.GetLinkDocument()

create a category filter

coll = FilteredElementCollector(linkDoc, view.Id).OfCategory(BuiltInCategory.OST_DuctAccessory).WhereElementIsNotElementType().ToElements()

#coll_list = list(coll)

TransactionManager.Instance.EnsureInTransaction(doc)

element_to_hide =

for ele in coll:
param = ele.LookupParameter(parameterName)
if param and param.AsDouble() == parameterValue:
element_to_hide.append(ele.Id)

view.HideElements(element_to_hide)
#out.append(ele)

TransactionManager.Instance.TransactionTaskDone()

uidoc.RefreshActiveView()

@prasad.chavan

paste your code with </>

import clr

clr.AddReference("RevitAPI")
from Autodesk.Revit import DB
from Autodesk.Revit.DB import FilteredElementCollector, BuiltInCategory

clr.AddReference("RevitAPIUI")
from Autodesk.Revit.UI import *

clr.AddReference("System")
from System.Collections.Generic import List

clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument
uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
view = uidoc.ActiveView
# 0️⃣ Preparing input from dynamo to revit

linkInst = UnwrapElement(IN[0])
parameterName = "Chamber Depth"
parameterValue = (1800)/304.8

linkDoc = linkInst.GetLinkDocument()
# 1️⃣ create a category filter

coll = FilteredElementCollector(linkDoc, view.Id).OfCategory(BuiltInCategory.OST_DuctAccessory).WhereElementIsNotElementType().ToElements()

# 2️⃣coll_list = list(coll)

TransactionManager.Instance.EnsureInTransaction(doc)

element_to_hide = []

for ele in coll:
    param = ele.LookupParameter(parameterName)
    if param and param.AsDouble() == parameterValue:
        element_to_hide.append(ele.Id)

view.HideElements(element_to_hide)
# 3️⃣ out.append(ele)

TransactionManager.Instance.TransactionTaskDone()

uidoc.RefreshActiveView()

KR

Andreas

1 Like

What’s the reason for automating this? Why not use the Visibility Graphics overrides or a filter?

2 Likes

I was just curious to know if there is a method to hide the linked elements