What you can do with View Filters in the 2014 API

Here’s are the new Filter items for the View class in 2014:

  • AddFilter – The filter will be added with default overrides, so there will be no change in the view’s display.
  • GetFilterOverrides – Returns all graphic overrides of a specific filter in the view
  • GetFilters – Returns the ids of the filters applied to the view
  • GetFilterVisibility – Returns true if the elements associated with a specific filter are visible in the view
  • IsFilterApplied – Returns true if a specific filter is applied to the view
  • RemoveFilter
  • SetFilterOverrides – Set the OverrideGraphicSettings for a filter in a view. Adds the filter to the view if it hadn’t been previously added.
  • SetFilterVisibility – Set the visibility of a specific filter (true / false) for a view. Adds the filter to the view if it hadn’t been previously added.
public void Filter2014Sample()
    UIDocument uidoc = this.ActiveUIDocument;
    Document doc = uidoc.Document;
    View view = doc.ActiveView;

    TaskDialog.Show("Boost Your BIM","# of filters applied to this view = " + view.GetFilters().Count);

    // create list of categories that will for the filter
    IList<ElementId> categories = new List<ElementId>();
    categories.Add(new ElementId(BuiltInCategory.OST_Walls));

    // create a list of rules for the filter
    IList<FilterRule> rules = new List<FilterRule>();
    // This filter will have a single rule that the wall type width must be less than 1/2 foot
    Parameter wallWidth = new FilteredElementCollector(doc).OfClass(typeof(WallType)).FirstElement().get_Parameter(BuiltInParameter.WALL_ATTR_WIDTH_PARAM);
    rules.Add(ParameterFilterRuleFactory.CreateLessRule(wallWidth.Id, 0.5, 0.001));

    ParameterFilterElement filter = null;
    using (Transaction t = new Transaction(doc, "Create and Apply Filter"))
        filter =  ParameterFilterElement.Create(doc, "Thin Wall Filter", categories, rules);

    string filterNames = "";
    foreach (ElementId id in view.GetFilters())
        filterNames += doc.GetElement(id).Name + "\n";
    TaskDialog.Show("Boost Your BIM","Filters applied to this view: " + filterNames);

    // Create a new OverrideGraphicSettings object and specify cut line color and cut line weight
    OverrideGraphicSettings ogs = new OverrideGraphicSettings();
    ogs.SetCutLineColor(new Color(255,0,0));

    using (Transaction t = new Transaction(doc, "Set Override Appearance"))

15 thoughts on “What you can do with View Filters in the 2014 API

  1. So, I am curious if the Revit 2014 API has a “RemoveLineStyle” feature? I know I can control the color, weight, line pattern (from a list) but I have never been able to DELETE line styles (and trust me.. those can get out of hand quickly).

    • Line Styles are Revit elements, so you should be able to use these to find the styles and then Document.Delete to remove them.
      CurveElement..::..GetLineStyleIds Method – Retrieves the set of available line style Element Ids.
      CurveElement..::..LineStyle Property – The line style of this curve element. (returns the Line Style element)

  2. Hello!
    But if i want to create filter by “Uconnected Height”?
    How should i do it, because there is no exist in filter option sort field like that.

    • Hi,

      You can change this line to get whatever parameter you want.


      Parameter wallWidth = new FilteredElementCollector(doc).OfClass(typeof(WallType)).FirstElement().get_Parameter(BuiltInParameter.WALL_ATTR_WIDTH_PARAM);

      • Thanks for quick answer
        Ye i’ve thougth so too, for example i’ve wanted to use BuiltInParameter.WALL_USER_HEIGHT_PARAM parameter (Unconnected height) but i have null value parameter.
        or for examle COMMENTS i have the same situation.
        Parameter wallWidth = new FilteredElementCollector(doc).OfClass(typeof(WallType)).FirstElement().get_Parameter(BuiltInParameter.WALL_USER_HEIGHT_PARAM);
        And surely i cant create rules…

        • This code is getting a parameter from a wall type. If you want to get a parameter from a wall instance then you would need to change the OfClass statement.

          Parameter wallWidth = new FilteredElementCollector(doc).OfClass(typeof(WallType)).FirstElement().get_Parameter(BuiltInParameter.WALL_ATTR_WIDTH_PARAM);

          • Thanks again Harry,
            for now i’ve got this parameter, but other problem is i cant add the rule with those parameter 😦
            rules.Add(ParameterFilterRuleFactory.CreateGreaterRule(wallWidth.Id, 5));
            i means that rule has been added but it cant be apply in model.
            View Filter show me all walls, but shoul show more than 5 meters.

            Is there way to implement filtering for elementId collection?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s