From this code from Autodesk I managed to create a pyRevit script that isolatestemporary untagged rebars if they are tagged with MRA or independent tag:
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import FilteredElementCollector, MultiReferenceAnnotation, IndependentTag, ElementId, Dimension, BuiltInCategory, Transaction
from System.Collections.Generic import List
uidoc = __revit__.ActiveUIDocument
doc = __revit__.ActiveUIDocument.Document
view = doc.ActiveView
def TemporarilyIsolateRebarSetsNotTaggedWithMRAorIndependentTag():
fec = FilteredElementCollector(doc).OfClass(MultiReferenceAnnotation)
mraIds = set()
for MRA in fec:
if MRA is None:
continue
if MRA.TagId == ElementId.InvalidElementId:
continue
dimension = doc.GetElement(MRA.DimensionId)
if dimension is None:
continue
mraType = doc.GetElement(MRA.GetTypeId())
if mraType is None:
continue
referenceCategoryId = mraType.ReferenceCategoryId
dimRefs = dimension.References
for reference in dimRefs:
elem = doc.GetElement(reference.ElementId)
if elem is None:
continue
if elem.Category.Id == referenceCategoryId:
mraIds.add(elem.Id)
all_rebar_element_ids = set([element.Id for element in FilteredElementCollector(doc, view.Id).OfCategory(BuiltInCategory.OST_Rebar)])
non_mra_rebar_element_ids = all_rebar_element_ids - mraIds
independentTagIds = set()
for independentTag in FilteredElementCollector(doc, view.Id).OfClass(IndependentTag):
independentTagIds.update([id for id in independentTag.GetTaggedLocalElementIds()])
non_mra_or_independent_tag_rebar_element_ids = non_mra_rebar_element_ids - independentTagIds
with Transaction(doc, 'Temporarily Isolate Untagged Rebars') as t:
t.Start()
view.IsolateElementsTemporary(List[ElementId](non_mra_or_independent_tag_rebar_element_ids))
t.Commit()
TemporarilyIsolateRebarSetsNotTaggedWithMRAorIndependentTag()