Filter for Doors with specific FromRoom or ToRoom values

By Saikat Bhattacharya

Is there a way to filter for doors with specific FromRoom or ToRoom values?

The following code snippet shows how we can create a filter for doors in a Revit model which have a specific ToRoom value set to a room name. This code can be modified and extended for specific requirements.

using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
 
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
 
namespace Revit.SDK.Samples.HelloRevit.CS
{
  [Transaction(TransactionMode.Manual)]
  public class Command : IExternalCommand
  {
    public Result Execute(ExternalCommandData commandData,
      ref string message,
      ElementSet elements)
    { 
      Document doc = 
        commandData.Application.ActiveUIDocument.Document;
 
      FilteredElementCollector coll = 
        new FilteredElementCollector(doc)
        .OfCategory(BuiltInCategory.OST_Doors)
        .OfClass(typeof(FamilyInstance));
 
      IEnumerable doors = 
        from FamilyInstance f in coll 
        where f.ToRoom.Name == "Room 1" 
        select f;
 
      foreach (FamilyInstance door in doors)
      {
        TaskDialog.Show("Door Name", door.Name);
      }
       return Result.Succeeded;
    }
  }         
}

 

While working with doors and rooms using the API, this blog-post might also be relevant to review, while on this topic.


Comments

One response to “Filter for Doors with specific FromRoom or ToRoom values”

  1. Hi Saikat,
    Name property may be not unique since two rooms could have the same name.
    Also, toroom and fromroom properties are not reliable in some cases.
    http://thebuildingcoder.typepad.com/blog/2011/03/unreliable-room-properties.html
    Best regards,
    Rudolf

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading