This blog post illustrates an example of how we can use the parameter filter to extract rooms based on the Phases they are assigned to. For the sake of discussion, let us assume we have a Revit model containing a set of four rooms in the current view (a floor plan) that are assigned the ‘New Construction’ which is also the phase that the active view is assigned to. Using the code snippet below, you can extract the rooms that are assigned to a different phase (say ‘ADSK’ phase) even though you cannot see them visibly in the active view (since the phase of the active view is not set to ‘ADSK’ phase).
The approach is rather simple. First we shall create a filter to access the specific phase in the model, which in this case is called ‘ADSK’. Then we create a new filter to extract all the SpatialElement types in the current model which has the ROOM_PHASE built-in parameter set to the phase we are looking for. The following code snippet provides the details of using this approach and using ParameterValueProvider class as well.
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Linq;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using Autodesk.Revit.ApplicationServices;
namespace Revit.SDK.Samples.HelloRevit.CS
{
[Transaction(TransactionMode.Manual)]
public class Command : IExternalCommand
{
Autodesk.Revit.ApplicationServices.Application app = null;
public Result Execute(ExternalCommandData commandData,
ref string message,
ElementSet elements)
{
// First filter for phase
UIDocument uiDoc = commandData.Application.ActiveUIDocument;
var phaseColl = new FilteredElementCollector(uiDoc.Document)
.OfClass(typeof(Phase));
IEnumerable<Phase> phases = from Phase f in
phaseColl where f.Name == "ADSK" select f;
var collector = new FilteredElementCollector(uiDoc.Document);
// Specify the class for the filter
collector.OfClass(typeof(Autodesk.Revit.DB.SpatialElement));
// Work with Parameter filter
var phaseProvider = new ParameterValueProvider(
new ElementId(BuiltInParameter.ROOM_PHASE));
FilterElementIdRule phaseRule = new FilterElementIdRule(
phaseProvider,
new FilterNumericEquals(),
phases.FirstOrDefault<Phase>().Id);
ElementParameterFilter phaseFilter =
new ElementParameterFilter(phaseRule);
collector.WherePasses(phaseFilter);
TaskDialog.Show("Number of spaces with ADSK phase is ",
collector.ToElements().Count.ToString());
return Result.Succeeded;
}
}
}