Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

how to verify label on element using revit api?

10 REPLIES 10
SOLVED
Reply
Message 1 of 11
prasannamurumkar
1010 Views, 10 Replies

how to verify label on element using revit api?

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?

 

10 REPLIES 10
Message 2 of 11

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.

Message 3 of 11

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.

 

Message 4 of 11

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
                       }
                    }
                }

Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

Message 5 of 11

 Element e = doc.GetElement(eid);

able to get element.For this

 IndependentTag Doortag = e as IndependentTag;

 Doortag is showing null.

 

Message 6 of 11

Hi @prasannamurumkar,

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.


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

Message 7 of 11

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?

Message 8 of 11

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.

 

 


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

Message 9 of 11

thank you it works fine.

Message 10 of 11

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.

 

Message 11 of 11

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 wellSmiley Happy

 


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community