hook is present in bathroom in given project.
Now wants to verify whether this hook is labeled by"HK" using revit api?
how do we that?
Solved! Go to Solution.
Solved by naveen.kumar.t. Go to Solution.
Solved by naveen.kumar.t. Go to Solution.
Assuming your question is about Tags (IndependentTag class in Revit API): tags are dependents of model elements. This means if you delete the element they will be deleted, then you can retrieve the tag ElementId and Rollback the transaction. Then retrieve the TagText property of the tag and compare it to "HK" or anything else.
Thank you for reply.
1.able to retrive tag
var doortag = new HashSet<ElementId>(collector1.OfClass(typeof(IndependentTag)).OfCategory(BuiltInCategory.OST_DoorTags).OfType<IndependentTag>().Select(x => x.GetTaggedLocalElement().Id).Where(x => x != null));
2.Able to retrive ElementID of tags.
foreach (ElementId i in doortag)
3.How to retrive Tag text property and how to compare with any particular name?
Could you give code for that.
Hi @prasannamurumkar ,
I hope this will help
foreach(ElementId eid in tagElementIds) { Element e = doc.GetElement(eid); IndependentTag Doortag = e as IndependentTag; if(Doortag!=null) { if(Doortag.TagText=="Name to compare") { //Your code } } }
Element e = doc.GetElement(eid);
able to get element.For this
IndependentTag Doortag = e as IndependentTag;
Doortag is showing null.
Your code collects the door not the door tag.
You can't cast door as independent tag.
Collect all doortags not doors and from the collected doortags try to get the tagtext.
but how to collect tags tried this one but not getting collect.
IEnumerable<Element> roomTags = new FilteredElementCollector(activeDoc, activeDoc.ActiveView.Id).OfCategory(BuiltInCategory.OST_RoomTags).WhereElementIsNotElementType().ToElements();
is this right?
or sholud try something else?
Hi @prasannamurumkar ,
Here the question is which tags you want to collect?
Do you want to collect Roomtags or DoorTags?
this code will help you to collect RoomTags
FilteredElementCollector Collector = new FilteredElementCollector(doc,doc.ActiveView.Id).OfCategory(BuiltInCategory.OST_RoomTags).WhereElementIsNotElementType(); IList<ElementId> eids = Collector.ToElementIds() as IList<ElementId>; foreach(ElementId eid in eids) { Element e = doc.GetElement(eid); RoomTag IT = e as RoomTag; string s=IT.TagText; }
and this code will help you to collect DoorTags
FilteredElementCollector Collector = new FilteredElementCollector(doc,doc.ActiveView.Id).OfCategory(BuiltInCategory.OST_DoorTags).WhereElementIsNotElementType(); IList<ElementId> eids = Collector.ToElementIds() as IList<ElementId>; foreach(ElementId eid in eids) { Element e = doc.GetElement(eid); IndependentTag IT = e as IndependentTag; string s=IT.TagText; }
I tested the above codes and both are working fine for me.
Hi
Do we able to get relation between tag and its element?
as in above case able to get independent tags of particular category.
for eg having 6 doors got 6 door tags in above case
suppose one of door does not have tag then it should able to find particular door does not having tag.
so it is require find relation between element category and element tag category.
Hi @prasannamurumkar ,
try using the below code
this code will highlight the elements which are not taggged
IList<ElementId> ElementsWithoutTag = new List<ElementId>(); foreach(Element e in new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Doors).OfClass(typeof(FamilyInstance))) { if(new FilteredElementCollector(doc).OfClass(typeof(IndependentTag)).Cast<IndependentTag>().FirstOrDefault(q=>q.TaggedLocalElementId==e.Id)==null) { ElementsWithoutTag.Add(e.Id); } }
uidoc.Selection.SetElementIds(ElementsWithoutTag);
uidoc.RefreshActiveView();
If this helped solve your problem please mark it as solution, so other users can get this solutions as well