Find Multi-Rebar Annotation Rebar elements

Find Multi-Rebar Annotation Rebar elements

Anonymous
Not applicable
2,029 Views
6 Replies
Message 1 of 7

Find Multi-Rebar Annotation Rebar elements

Anonymous
Not applicable

How can I get the rebar elements which were used for creating Multi-Rebar Annotation? The purpose is to find rebar elements with Multi-Rebar Annotation with not set tag. I can find all Rebar elements using FilteredElementCollector with filtering by Category (BuiltInCategory.OST_Rebar) and also Multi-Rebar Annotation elements (BuiltInCategory.OST_MultiReferenceAnnotations) but how to find a connection between them?

0 Likes
Accepted solutions (1)
2,030 Views
6 Replies
Replies (6)
Message 2 of 7

longt61
Advocate
Advocate
Accepted solution

Using Revit Lookup, you can easily find this connection. 

From the selected MultiRefenceAnnotation, you can get the dimension in use. Then, you can get a list of References from the Dimension.References. Each of these references refers to a rebar of the tagged rebar set.

Message 3 of 7

Anonymous
Not applicable

Thank you very much, it was easier then I assumed.

0 Likes
Message 4 of 7

tom.slasletten
Participant
Participant

Does not work in Revit 2023. They destroyed Multi-Rebar annotation API. I cant select host of a multi-rebar annotations anymore using scripts.

0 Likes
Message 5 of 7

aysenakahraman98
Participant
Participant

perfectly working for 2022 thank you so much 😀

0 Likes
Message 6 of 7

tom.slasletten
Participant
Participant

Here is a code I got from Autodesk to workaround this issue: 

// This is a Document Macro that iterates through all MultiReferenceAnnotation elements in the document
// and collects the referenced rebar elements for MultiReferenceAnnotation elements that contain tag.
public void SelectRebarSetsTaggedWithMRA()
{
FilteredElementCollector fec = new FilteredElementCollector(Document).OfClass(typeof(MultiReferenceAnnotation));
for(FilteredElementIterator iter = fec.GetElementIterator(); !iter.IsDone(); iter.MoveNext())
{
MultiReferenceAnnotation MRA = iter.Current as MultiReferenceAnnotation;
if(MRA == null)
continue;

// if the MRA has no tag not interested
if(MRA.TagId == ElementId.InvalidElementId)
continue;

Dimension dimension = Document.GetElement(MRA.DimensionId) as Dimension;
if(dimension == null)
continue;

MultiReferenceAnnotationType mraType = Document.GetElement(MRA.GetTypeId()) as MultiReferenceAnnotationType;
if(mraType == null)
continue;

// this is always OST_Rebar
ElementId referenceCategoryId = mraType.ReferenceCategoryId;

// get the dimension references
ReferenceArray dimRefs = dimension.References;

// append the element ids referenced by the dimension if the element category id mathches the reference category id from the MultiReferenceAnnotationType
HashSet<ElementId> rebarIds = new HashSet<ElementId>();
foreach (Reference reference in dimRefs)
{
Element elem = Document.GetElement(reference.ElementId);
if(elem == null)
continue;

if(elem.Category.Id == referenceCategoryId)
rebarIds.Add(elem.Id);
}

// the needed ids for the current MRA element are in the rebarIds, do whatever you need to do with them
Selection selection = Application.ActiveUIDocument.Selection;
selection.SetElementIds(rebarIds);
}
}

0 Likes
Message 7 of 7

tom.slasletten
Participant
Participant

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

0 Likes