Here’s a question from a reader who is taking my Revit API course at Udemy.com
“Is it possible via the api to verify if all instances of a particular category have tags? For instance, if I have 100 light fixtures in a project, I would like to verify that each one has a tag and if not, then to find the ones without tags.”
Below is a bit of code that uses the IndependentTag.TaggedLocalElementId property to select all Lighting Fixtures that have no tags.
public void notTagged()
{
Document doc = this.ActiveUIDocument.Document;
UIDocument uidoc = this.ActiveUIDocument;
SelElementSet sel = SelElementSet.Create();
foreach (Element e in new FilteredElementCollector(doc)
.OfCategory(BuiltInCategory.OST_LightingFixtures)
.OfClass(typeof(FamilyInstance)))
{
if (new FilteredElementCollector(doc)
.OfClass(typeof(IndependentTag))
.Cast<IndependentTag>()
.FirstOrDefault(q => q.TaggedLocalElementId == e.Id) == null)
sel.Add(e);
}
uidoc.Selection.Elements = sel;
uidoc.RefreshActiveView();
}