Filter for linked-In models

I’m trying to filter a list of elements, I want to filter out any model that is NOT a linked model. But so far I have not had success finding a way to check if an element is from a linked model or not.

I have used the dir() function to find a list of attributes, however none of the attributes that I have tested return any values useful for filtering( either all the same or all different).

So far my code takes a view list input, it grabs all the elements in each view and sorts out specific elements, then makes a change to all elements selected.

(Sorry for how dirty the code looks, lots of debugging output’s)

RepeatLoop = 0
import time
while RepeatLoop < 1:
RepeatLoop = RepeatLoop + 1
import clr
clr.AddReference(“RevitNodes”)
import Revit
clr.ImportExtensions(Revit.Elements)
import time

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
uidoc = DocumentManager.Instance.CurrentUIDocument

clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *


import System
from System.Collections.Generic import *


import sys
pyt_path = r'C:\program Files (x86)\IronPython 2.7\Lib'
sys.path.append(pyt_path)


DataEnteringNode = IN


def ProcessList(_func, _list):
	return map( lambda x: ProcessList(_func, x) if type(x)==list else _func(x), _list )


def Unwrap(item):
	return UnwrapElement(item)

errorReport = ""
Output = ""
PreOutput = ""
ViewListCount = 0
View = Unwrap(IN[0][0])
OutputList = []
StageLevel = "0"
ItemList = []
ids = List[ElementId]()
PassCount = 0
FailCount = 0
Item = []
ItemNames = []

IsHidden = 0
ListCount = 0
LoopList = []

FamilyList = []
FamilyList.Add("Family List")
FamilyListWorkset = []
FamilyListWorkset.Add("FL Workset Id")
FamilyListTypeId = []
FamilyListTypeId.Add("FL Type Id")

while ViewListCount < len(IN[0]):
	LoopList.Add("Loop Started")
	ListCount = ListCount + 1
	TransactionManager.Instance.ForceCloseTransaction()
	#uidoc.RequestViewChange( View )
	LoopList.Add(View)
	LoopList.Add(ListCount)
	ViewListCount = ViewListCount + 1
	if ViewListCount < len(IN[0]):
		View = Unwrap(IN[0][ViewListCount])
	collector = FilteredElementCollector(doc,View.Id).ToElements();
	
	for i in Unwrap(collector):
		if Element.Name.GetValue(i) != "ElectricalSystem" and Element.Name.GetValue(i).startswith("Elevation") != True and Element.Name.GetValue(i).startswith("Space") != True and Element.Name.GetValue(i).startswith("Workshop") != True and Element.Name.GetValue(i).startswith("Standard") != True and Element.Name.GetValue(i).startswith("XHHW") != True and Element.Name.GetValue(i).startswith("GFCI") != True and Element.Name.GetValue(i).startswith("Model ") != True and Element.Name.GetValue(i).startswith("Section ") != True and Element.Name.GetValue(i).startswith("Hall ") != True and Element.Name.GetValue(i).startswith("3D ") != True and Element.Name.GetValue(i).startswith("Mechanical") != True and Element.Name.GetValue(i).startswith("North") != True and Element.Name.GetValue(i).startswith("South") != True and Element.Name.GetValue(i).startswith("West") != True and Element.Name.GetValue(i).startswith("East") != True and Element.Name.GetValue(i).startswith("Duct") != True and Element.Name.GetValue(i).startswith("STB ") != True:
			LoopList.Add(i)
			LoopList.Add(Element.Name.GetValue(i))
			if Element.Name.GetValue(i) == "Grid Line":
				LoopList.Add("Pass1")
				ItemNames.Add(Element.Name.GetValue(i))	
				Item.Add(i)
				if not i.IsHidden(View) and i.CanBeHidden(View):				
					PassCount = PassCount + 1
					ids.Add(i.Id)
					LoopList.Add("Added to ids")
			else:			
				FailCount = FailCount + 1
				LoopList.Add("Fail1")
					
					
			if Element.ToString(i) == "Autodesk.Revit.DB.Grid":
				LoopList.Add("Pass2")
				ItemNames.Add(Element.ToString(i))
				Item.Add(i)
				if not i.IsHidden(View) and i.CanBeHidden(View):				
					PassCount = PassCount + 1
					ids.Add(i.Id)
					LoopList.Add("Added to ids")
					FamilyList.Add("!! Object Added !!")
					FamilyList.Add("Name:")
					FamilyList.Add(i.Name)
					FamilyList.Add("Id:")
					FamilyList.Add(i.Id)
					FamilyList.Add("Object:")
					FamilyList.Add(i)
					FamilyList.Add("Get Type Id:")
					FamilyList.Add(i.GetTypeId())
					FamilyList.Add("Type:")
					FamilyList.Add(i.GetType())
					FamilyList.Add("Group Id:")
					FamilyList.Add(i.GroupId)
					#FamilyList.Add(i.Category)
					#FamilyList.Add(i.Document)
					FamilyList.Add("Workset Id:")
					FamilyList.Add(i.WorksetId)
					#FamilyList.Add(i.Location)
					FamilyList.Add("Owner View Id:")
					FamilyList.Add(i.OwnerViewId)
					FamilyList.Add("Level Id:")
					FamilyList.Add(i.LevelId)
					FamilyList.Add(i.GetExternalFileReference)
					FamilyList.Add(i.GetExternalResourceReference)
					FamilyList.Add(i.GetExternalResourceReferences)
					#FamilyList.Add(i.GetMonitoredLinkElementIds())
					#FamilyList.Add(i.GetMonitoredLocalElementIds())
					#FamilyList.Add(i.GetEntity)
					#FamilyList.Add(i.GetGeneratingElementIds)
					#FamilyList.Add(i.GetAnalyticalModel())
					#FamilyList.Add(i.GetAnalyticalModelId())
					FamilyList.Add(dir(i))
					FamilyListWorkset.Add(i.WorksetId)
					FamilyListTypeId.Add(i.GetTypeId())
					
				
			else:			
				FailCount = FailCount + 1
				LoopList.Add("Fail2")
		
		
			
	doc = DocumentManager.Instance.CurrentDBDocument
	LoopList.Add("Check if list is populated")
	LoopList.Add(len(ids))
	if len(ids) != 0:	
		TransactionManager.Instance.EnsureInTransaction(doc)\
		#the code: View.HideElements(ids) performs the task of hiding the elements within the view called View.
		#View.HideElements(ids)
		time.sleep(0.1)
		uidoc = DocumentManager.Instance.CurrentUIDocument
		TransactionManager.Instance.TransactionTaskDone()
		ids = List[ElementId]()
		IsHidden = IsHidden + 1
		LoopList.Add("Current View")
		LoopList.Add(View)
		LoopList.Add("List Hidden")
	
	p = 0
	while p < 50:
		LoopList.Add("Loop Ended /////////////////////// Loop Ended")
		LoopList.Add(ListCount)	
		LoopList.Add("Loop Ended /////////////////////// Loop Ended")
		p = p + 1
	
			
#Assign your output to the OUT variable.
ListCountOutput = "List Count: " + str(ListCount)
IsHiddenOutput = "Lists Hidden: " + str(IsHidden)
PassCountOutput = "Items Passed: " + str(PassCount)
FailCountOutput = "Items Failed: " + str(FailCount)
ItemsHidden = "Items have been hidden"
if (PassCount + IsHidden) == 0:
	ItemsHidden = "All items hidden already"

OUT = RepeatLoop, ids, Item, ItemNames, PassCountOutput, FailCountOutput, IsHiddenOutput, ListCountOutput, ItemsHidden, LoopList, IN[1], FamilyList, FamilyListWorkset, FamilyListTypeId;