Removing all Orphaned Linked Element Tags in View

Hey All,

Has anyone ever tried to remove tags from views on linked elements? I’m trying to remove all tags that’s lost their host. But when I try to run any kind of dynamo (Get all elements of Category in View) or python method (Filtered Element Collector) for collecting all elements of type in view I get the “Internal Error”

And even with PyRevit it doesn’t seem to like it. I’m a bit lost as to how I can move forward with this.

Any Ideas??

Hello @shuzmm

try this

import clr
import sys
import System
from Autodesk.DesignScript.Geometry import *
import Autodesk.DesignScript.Geometry as DS

import Autodesk
from Autodesk.Revit.DB import *
import Autodesk.Revit.DB as DB

import Revit

import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument

ueWrapper = None
wrappers = clr.GetClrType(Revit.Elements.ElementWrapper).GetMethods()
for w in wrappers:
	if w.ToString().startswith("Revit.Elements.UnknownElement"):
		ueWrapper = w

allTags = FilteredElementCollector(doc).OfClass(IndependentTag).WhereElementIsNotElementType().ToElements()
lostTags = [ueWrapper.Invoke(None, (t, True) ) for t in allTags if t.TaggedElementId.LinkInstanceId == ElementId.InvalidElementId ]

OUT = lostTags

Thanks @c.poupin you are a python wizard I had no idea these methods existed!

1 Like