how to gets relation of element with its tag or its label?

how to gets relation of element with its tag or its label?

prasannamurumkar
Advocate Advocate
3,348 Views
12 Replies
Message 1 of 13

how to gets relation of element with its tag or its label?

prasannamurumkar
Advocate
Advocate

I have doors.

I have door tags

want to verify the whether  particular tags present on that  particular door?

 

0 Likes
3,349 Views
12 Replies
Replies (12)
Message 2 of 13

jeremytammik
Autodesk
Autodesk

Did you RTFM?

 

https://apidocs.co/apps/revit/2019/759306d1-5168-ef9a-91e4-494c7eff0b5d.htm

 

TaggedLocalElementId looks like it will do the job.

 

Cheers,

 

Jeremy

 

 

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 3 of 13

jeremytammik
Autodesk
Autodesk

Also, you already asked this same question and received the same answer before:

 

https://forums.autodesk.com/t5/revit-api-forum/i-want-to-check-whether-tag-is-present-on-door-by-api...

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 4 of 13

prasannamurumkar
Advocate
Advocate

At that time i thought that answer is correct but actually answer is wrong.

He answered as tag contains same element  id as that of tag.

but tags are different Id than the element ID

also he  given tags we get like this

var doorTagsIds = new HashSet<ElementId>(collector.OfClass(typeof(IndependentTag)).OfCategory(BuiltInCategory.OST_DoorTags).OfType<IndependentTag>().Select(x => x.GetTaggedLocalElement()?.Id).Where(x => x != null));

 by this not able to collect door tag it just collects id s of door only.

0 Likes
Message 5 of 13

jeremytammik
Autodesk
Autodesk

It collects all independent tags AND the element ids of the doors that they tag.

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 6 of 13

TWhitehead_HED
Contributor
Contributor

Hi All,

 

Given the above property is no longer valid in the current API, what is an updated solution? 

0 Likes
Message 7 of 13

jeremy_tammik
Alumni
Alumni

I would assume that this can easily be discovered by snooping the element and its tag and their properties using RevitLookup and other Revit BIM database exploration tools. Have you taken a look at that?

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 8 of 13

jrostar
Participant
Participant
You could also assume that people come to public forums asking for help after they have already spent time trying to discover the answer themselves and are hoping that knowledgeable people from the community would be willing to help.
Message 9 of 13

jeremy_tammik
Alumni
Alumni

Yes, indeed! Sometimes I do, and sometimes they have, and sometimes they have not. It takes all sorts...

   

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 10 of 13

TWhitehead_HED
Contributor
Contributor

There's a saying about assuming... I'll leave it up to you to find on the internet.  

 

For others scraping through these posts looking for a modicum of actual help, here's how I ended up solving it with help from @Mohamed_Arshad (who actually provided some guidance). 


using (Transaction trans = new Transaction(doc, "Tag Parent Doors"))
            {
                trans.Start();

                foreach (FamilyInstance door in doors)
                {
                    if (new FilteredElementCollector(doc, currentView.Id)
                         .OfCategory(BuiltInCategory.OST_DoorTags)
                         .OfClass(typeof(IndependentTag))
                         .Cast<IndependentTag>()
                         .SelectMany(x => x.GetTaggedLocalElementIds())
                         .Where(x => x == door.Id).Any())
                    {
                        skipCount++;
                        continue;
                    }
                }
            }
Message 11 of 13

DanielKP2Z9V
Advocate
Advocate

If anyone lands here looking for a reference how to switch selection between tags and their hosts I have commands to SelectAssociatedTags and SelectElementsHostedBySelectedTags 

0 Likes
Message 12 of 13

DanielKP2Z9V
Advocate
Advocate

correction, this doesn't seem to work however on rooms and areas - if anyone figured out how to associate room/area tags to their hosts that would be very helpful

0 Likes
Message 13 of 13

jeremy_tammik
Alumni
Alumni

Many thanks to Tom, Mohamed and Daniel for digging in and helping with this!

  

I shared their answers on the blog:

  

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open