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<FamilyInstance> 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.