Hide Elements by Selection from a Linked Model

I am trying to hide elements from a linked model by selection. This is in case we are not owners of the linked model and hence cannot assign parameters inside the linked model. In this particular case, there is no parameter that I can use to filter elements and have to resort to manually hiding elements. This is related to showing the sequence of construction. The error I am receiving is this:

**One of the elements cannot be hidden. **
Parameter name: elementIdSet

Code Below:

doc = revit.doc
uidoc = revit.uidoc

class CustomISelectionFilter(ISelectionFilter):
    def __init__(self, category_name, document):
        self.category_name = category_name
        self.document = document

    def AllowElement(self, element):
        some_type = self.document.GetElement(element.GetTypeId())
        type_name = some_type.FamilyName

        if type_name == "Linked Revit Model":
            return True
            if element.Category.Name == self.category_name:
                return True
                return False

    def AllowReference(self, ref, point):
        element = self.document.GetElement(ref)
        some_type = revit.doc.GetElement(element.GetTypeId())
        type_name = some_type.FamilyName

        if type_name == "Linked Revit Model":
            li = clr.Convert(element, type(element))
            linked_document = li.GetLinkDocument()
            element = linked_document.GetElement(ref.LinkedElementId)

        if element.Category.Name == self.category_name:
            return True
            return False

def HideElements(view, elements):
    elsids_can_be_hidden = []
    for i in elements:
    clist_ids = List[DB.ElementId](elsids_can_be_hidden)
    return None

with forms.WarningBar(title="Pick elements in linked model"):
          wall_collector_link=uidoc.Selection.PickObjects(ObjectType.LinkedElement,CustomISelectionFilter("Structural Framing", doc))
          listoflinkedelemeid = []
          for i in wall_collector_link:
              mylist = List[DB.ElementId](listoflinkedelemeid)
              activeView = revit.uidoc.ActiveGraphicalView
          except Exception as e:
              print (e)

I doubt this is possible at all.
I looked into it a while back and did not find a way.

Have you tried the CanBeHidden method on your elements?

I tried that first and that did not catch anything.

I thought so too after researching online but still wanted to ask in case someone has found a way. Thank you.

A not very elegant way, if the linked is workshared would be to create a routine that:

  1. Retains the selection of elements to hide
  2. Opens the linked model
  3. Puts the elements into a new workset “to be hidden”
  4. Reload the linked model and hides the newly created workset.