Quantcast
Channel: All Revit API Forum posts
Viewing all articles
Browse latest Browse all 67020

Re: Find Multi-Rebar Annotation Rebar elements

$
0
0

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()


Viewing all articles
Browse latest Browse all 67020


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>