0

I am trying to filter walls. For that I use

categories = List[ElementId]()
myId = ElementId(BuiltInCategory.OST_Walls)
categories.Add(myId)

..but this obviously doesn't return a valid ElementId, as when I print it, it has some negative value (and if I print "doc.GetElement(myId)", I get "None").

Then, indeed when creating the filter...

filter = ParameterFilterElement.Create(doc, "Walls filter", categories)

...I get an ArgumentException. I'm using Revit 2019 (with pyRevit). As far as I remember, it used to work with Revit 2018, but I don't see any reason it shouldn't anymore. What am I missing?

Thanks a lot!

Arnaud
  • 445
  • 4
  • 18

3 Answers3

1

You can simply use the filtered element collector OfCategory Method.

E.g., check out The Building Coder hints on filtered element collector optimisation.

Jeremy Tammik
  • 7,333
  • 2
  • 12
  • 17
  • Still, I don't understand: Doing "a = ElementId(BuiltInCategory.OST_Walls)" yields a negative Id, something like -2000011, although this exact same command is used in the examples found on ApiDocs.co for ParameterFilterElement. Does a negative Id mean that it isn't a valid element? Because indeed trying then something like "doc.GetElement(a)" yields None. Why isn't this working? Thanks! – Arnaud Mar 12 '19 at 13:30
  • in the Revit API, a negative element id is usually a built-in constant enumeration value. in this case, it is a BuiltInCategory enumeration value. you can look at it in the Visual Studio debugger and in the help file. non-built-in element ids are normally positive and sequential. – Jeremy Tammik Mar 13 '19 at 14:16
0

Apply an ElementCategoryFilter to the collector to get all the walls of the project. By using the following code you can filter any kind of category. I have tried this on Revit 2019.

FilteredElementCollector collector = new FilteredElementCollector(document);
ICollection<Element> walls = collector.OfCategory(BuiltInCategory.OST_Walls).ToElements();
Mah Noor
  • 83
  • 1
  • 11
0

I agree with @Mah Noor answer.

If you need to have a filter with multiple categories, you can use:

        ElementCategoryFilter wallFilter = new ElementCategoryFilter(BuiltInCategory.OST_Walls);
        ElementCategoryFilter windowFilter = new ElementCategoryFilter(BuiltInCategory.OST_Windows);
        LogicalOrFilter wallAndWindowFilter = new LogicalOrFilter(wallFilter, windowFilter);
        ICollection<Element> collection = new FilteredElementCollector(doc).WherePasses(wallAndWindowFilter);

Bonus tip, you may want to add .WhereElementIsNotElementType() or .WhereElementIsElementType() to your query.

Best regards

François

F. Robb
  • 46
  • 5