Find elements that are not tagged

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

Which schedules are on a sheet and which are not?

Jason wonders if there is an easy way to find out which schedules are on a sheet and which are not?

Yes, there is. Find all schedules and then find which ones have a corresponding ScheduleSheetInstance

Capture

public void schedulesSheets()
{
    UIDocument uidoc = this.ActiveUIDocument;
    Document doc = uidoc.Document;   
    IList<string> onSheet = new List<string>();
    IList<string> notOnSheet = new List<string>();
    
    foreach (ViewSchedule vs in new FilteredElementCollector(doc)
             .OfClass(typeof(ViewSchedule))
             .Cast<ViewSchedule>()
             .Where(q => !q.IsTitleblockRevisionSchedule && !q.IsInternalKeynoteSchedule))
    {
        // ScheduleSheetInstance.ScheduleId is the Id of the "master" schedule that generates this ScheduleInstance
        if (new FilteredElementCollector(doc)
            .OfClass(typeof(ScheduleSheetInstance))
            .Cast<ScheduleSheetInstance>()
            .FirstOrDefault(q => q.ScheduleId == vs.Id) == null)
            notOnSheet.Add(vs.Name);
        else
            onSheet.Add(vs.Name);
    }
    
    string data = "--- Schedules On Sheets = " + onSheet.Count() + Environment.NewLine;
    foreach (string s in onSheet)
    {
        data += s + Environment.NewLine;
    }
    data += Environment.NewLine + "--- Schedules Not On Sheets = " + notOnSheet.Count() + Environment.NewLine;
    foreach (string s in notOnSheet)
    {
        data += s + Environment.NewLine;
    }
    TaskDialog.Show("output",data);
}

Using the API to compare display performance in Revit 2014 & 2015

Autodesk has mentioned that Revit 2015 has much improved display performance.

Here’s an API command to open views, zoom in & out, and change the display style. It can be used to compare the same RVT in different versions of Revit (as shown here), different RVTs in the same version of Revit, different computers, graphics cards, etc.

2014-2015viewperf

Upgrading your API applications to a new Revit version

With the release of Revit 2015, you may be thinking about what needs to be done to get your 2013 and 2014 API programs working in 2015.

This video looks at some parts of the API that were marked obsolete in 2014 and removed in 2015. In upcoming posts I will show how to update projects like this so they can support multiple versions of Revit.

Logging time spent working in each Revit file

Here’s an example showing how the API can keep track of how long you are working in each RVT file, if that sort of thing is interesting to you. It should be a bit smarter to distinguish “working time” from time when you are at lunch, and what else would make this useful to you?