Let us see how to create various ElementParameterFilter code with the assistance of the RevitAddinCoder. Click on the ElementParameter Filter button,
or the menu item of the RevitAddinCoder,
then the ElementParameter Filter coder window will show up.
If we want to find all windows having height in the range of 3 feet and 5 feet, we can specify the BuiltInParameter as WINDOW_HEIGHT, the filter evaluators and their values, inverting or not, applying which element class filter and/or which category filter, what name the method should be, and where to put the method like the following:
Then the following code will be created automatically:
public static ICollection<ElementId> FindWindowsWithHeightInRange(RvtDocument doc)
{
ParameterValueProvider provider = new ParameterValueProvider(new ElementId((int)BuiltInParameter.WINDOW_HEIGHT));
FilterDoubleRule rule1 = new FilterDoubleRule(provider, new FilterNumericGreaterOrEqual(), 3, 10e-8);
ElementParameterFilter filter1 = new ElementParameterFilter(rule1);
FilterDoubleRule rule2 = new FilterDoubleRule(provider, new FilterNumericLessOrEqual(), 5, 10e-8);
ElementParameterFilter filter2 = new ElementParameterFilter(rule2);
return (new FilteredElementCollector(doc))
.OfCategory(BuiltInCategory.OST_Windows)
.WherePasses(filter1)
.WherePasses(filter2)
.ToElementIds();
}
If we want to find all walls bounding some rooms, we can specify the BuiltInParameter as WALL_ATTR_ROOM_BOUNDING, the filter evaluators and their values, inverting or not, applying which element class filter and/or which category filter first, what name the method should be, and where to put the method like the following:
Then the following code will be created automatically:
public static ICollection<ElementId> FindWallsBoundingRoom(RvtDocument doc)
{
ParameterValueProvider provider = new ParameterValueProvider(new ElementId((int)BuiltInParameter.WALL_ATTR_ROOM_BOUNDING));
FilterIntegerRule rule1 = new FilterIntegerRule(provider, new FilterNumericEquals(), 1);
ElementParameterFilter filter1 = new ElementParameterFilter(rule1);
return (new FilteredElementCollector(doc))
.OfClass(typeof(Autodesk.Revit.DB.Wall))
.WherePasses(filter1)
.ToElementIds();
}
If we want to find all walls in a demolished phase, we can specify the BuiltInParameter as PHASE_DEMOLISHED, the filter evaluators and their values, inverting or not, applying which element class filter and/or which category filter first, what name the method should be, and where to put the method like the following:
Then the following code will be created automatically:
public static ICollection<ElementId> FindWallsInDemolishedPhase(RvtDocument doc, ElementId id1)
{
ParameterValueProvider provider = new ParameterValueProvider(new ElementId((int)BuiltInParameter.PHASE_DEMOLISHED));
FilterElementIdRule rule1 = new FilterElementIdRule(provider, new FilterNumericEquals(), id1);
ElementParameterFilter filter1 = new ElementParameterFilter(rule1);
return (new FilteredElementCollector(doc))
.OfClass(typeof(Autodesk.Revit.DB.Wall))
.WherePasses(filter1)
.ToElementIds();
}
If we want to find all walls in a created phase, we can specify the BuiltInParameter as PHASE_CREATED, the filter evaluators and their values, inverting or not, applying which element class filter and/or which category filter first, what name the method should be, and where to put the method like the following:
Then the following code will be created automatically:
public static ICollection<ElementId> FindWallsInCreatedPhase(RvtDocument doc, ElementId id1)
{
ParameterValueProvider provider = new ParameterValueProvider(new ElementId((int)BuiltInParameter.PHASE_CREATED));
FilterElementIdRule rule1 = new FilterElementIdRule(provider, new FilterNumericEquals(), id1);
ElementParameterFilter filter1 = new ElementParameterFilter(rule1);
return (new FilteredElementCollector(doc))
.OfClass(typeof(Autodesk.Revit.DB.Wall))
.WherePasses(filter1)
.ToElementIds();
}
If we want to find all elements having a particular project parameter attached we can simply name the project parameter name and the method name like the following:
Then the following code will be created automatically:
public static ICollection<ElementId> FindElementsHavingProjectParameter(RvtDocument doc)
{
SharedParameterApplicableRule rule = new SharedParameterApplicableRule("MyParameter1");
ElementParameterFilter filter = new ElementParameterFilter(rule);
return (new FilteredElementCollector(doc))
.WherePasses(filter)
.ToElementIds();
}
If we want to find all rooms having room number in a specific range, we can specify the BuiltInParameter as ROOM_NUMBER, the filter evaluators and their values, inverting or not, applying which element class filter and/or which category filter first, what name the method should be, and where to put the method like the following:
Then the following code will be created automatically:
public static ICollection<ElementId> FindRoomsWithNumberInRange(RvtDocument doc)
{
ParameterValueProvider provider = new ParameterValueProvider(new ElementId((int)BuiltInParameter.ROOM_NUMBER));
FilterStringRule rule1 = new FilterStringRule(provider, new FilterStringGreater(), "10", false);
ElementParameterFilter filter1 = new ElementParameterFilter(rule1);
FilterStringRule rule2 = new FilterStringRule(provider, new FilterStringLess(), "20", false);
ElementParameterFilter filter2 = new ElementParameterFilter(rule2);
return (new FilteredElementCollector(doc))
.OfCategory(BuiltInCategory.OST_Rooms)
.WherePasses(filter1)
.WherePasses(filter2)
.ToElementIds();
}
ElementParameter Filter of RevitAddinCoder can take care of all these and much more.
Recent Comments