Hide Linked model categories?

I was wondering, would it be possible to create a script that is able to detect linked models and turn off a specified category?

For example, assuming I have explored all the traditional Revit ways of turning things on/off, can a script be written so that it can look at all the views and turn off all the matchlines/grids from all the linked models?

Probably yes.
the Revit API to handle linked elements visibility is new and not complete, it would work with 2024+

Maybe a better / manual workflow would be to play with view templates:

  • record view templates applied to every view,
  • edit them to ‘not take care of the linked elements category visibility’
  • create a template that does turn off categories in links and does just that, and apply it to every view
  • re apply previous templates

Bold stuff could be done in a script to get there faster if you have to do it on multiple models, if not, manually should be faster

2 Likes

I came back to this because I am now starting to use Revit 2025.

Part of this intent was to hide Levels, Grids, and Matchlines. Levels and Grids i am able to hide via filters, not matchlines unless I go to each view template, set to custom…

Unfortunately, other forget to place them on proper worksets that we can turn off globally.

I was able to create this

# -*- coding: utf-8 -*-
__title__   = "Hide Linked Matchlines"


import clr
clr.AddReference("RevitAPI")
clr.AddReference("RevitAPIUI")

from Autodesk.Revit.DB import *
from Autodesk.Revit.UI import *
from pyrevit import revit

# Access the current Revit document, UI document, and application
doc   = revit.doc
uidoc = revit.uidoc
app   = uidoc.Application

# This list will store all valid link-based element references
# corresponding to Matchlines found inside linked Revit models
link_refs = []

# ------------------------------------------------------------
# STEP 1: Collect Matchlines from all loaded Revit links
# ------------------------------------------------------------
for link_inst in FilteredElementCollector(doc).OfClass(RevitLinkInstance):
    # Each RevitLinkInstance represents a loaded linked model in the project
    link_doc = link_inst.GetLinkDocument()
    if not link_doc:
        # Skip if the link is unloaded or not currently accessible
        continue

    # Collect all Matchline elements within this linked document
    matchline_ids = FilteredElementCollector(link_doc)\
        .OfCategory(BuiltInCategory.OST_Matchline)\
        .WhereElementIsNotElementType()\
        .ToElementIds()

    # Skip if no Matchlines were found in this link
    if not matchline_ids:
        continue

    # For each Matchline element ID, create a cross-document Reference
    for eid in matchline_ids:
        try:
            # Get the element object from the link
            element = link_doc.GetElement(eid)
            # Create a reference that points to the linked element
            ref = Reference(element).CreateLinkReference(link_inst)
            # Add this reference to our master list for hiding
            link_refs.append(ref)
        except:
            # Some elements may fail to reference properly — ignore safely
            pass

# ------------------------------------------------------------
# STEP 2: Trigger Revit’s built-in “Hide Elements” command 
# ------------------------------------------------------------
if link_refs:
    # Select all collected linked Matchline references in the view
    uidoc.Selection.SetReferences(link_refs)

    # Use Revit's internal command ID for “Hide Elements”
    hide_cmd = RevitCommandId.LookupPostableCommandId(PostableCommand.HideElements)

    # This hides all currently selected elements in the active view
    app.PostCommand(hide_cmd)


I am needing help taking this up a notch by having a few modes

  • Active View: what I currently have
  • Select Views: hides them in the selected views
  • Select Sheets: hides them in the views that are on those sheets.

I haven’t been successful in the

  • Select Views and
  • Select Sheets

If anyone would like to take a stab a this and maybe get it working and share back. That would be great.