1

I've just started workin with Revit API and I have one question. I've been looking for a way now to filter Revit elements by Family. Here's my procedure: First I do a filtered element Collector to obtain all family symbos Ids.

Families = FilteredElementCollector(doc).OfClass(Family).ToElements()
for fam in Families:
    if fam.Name == 'Family Name':
        FamSymb = fam.ID

This should get me the family symbol Id. Then, I try to create the filtered element collector with this Id.

ElementFilter = FamilySymbolFilter(ElementId(FamSymb))
New_Collector = FilteredElementCollector(doc).WherePasses(ElementFilter).ToElementIds()

This gives me the following error: Microsoft.Scripting.ArgumentTypeException: expected BuiltInParameter, got ElementId.

I don't know why it is expecting a BuiltInParameter, if the FamilySymbolFilters ask for an element Id. Anyway, Any help will be highly appreciated. Thanks!

Cfun
  • 8,442
  • 4
  • 30
  • 62

2 Answers2

0

Welcome to the Revit API. You will probably save yourself some time, effort and head scratching by first of all working through the getting started material. Furthermore, it will help you to understand the difference between the family definition versus its types, which generate symbols in the project environment, which are placed as individual instances.

What you have named FamSymb is in fact an element id identifying the family you found. The error you see is caused by the fact that you are feeding that ElementId instance to the ElementId constructor. However, ElementId does not implement a (copy) constructor taking an element id argument. It does however implement one taking a BuiltInParameter, cf. the ElementId documentation.

You can straight away instantiate FamilySymbolFilter(FamSymb) (althopugh I would strongly recommend naming FamSymb differently).

Jeremy Tammik
  • 7,333
  • 2
  • 12
  • 17
  • Sorry for the late response. Thanks a lot! This worked perfectly. Thank you as well for the links and the information. I'm sure that'll come quite handy as I go deeper into the Revit API. – ANDRES RAMOS May 16 '20 at 16:34
0

I think you already have the code you need - but are just adding an unecessary condition.

It looks like youre searching for a Family called 'Family Name'. Adjusting your code like this fetches all families as Family objects, and checks for one called 'Family Name':

Families = FilteredElementCollector(doc).OfClass(Family)
for fam in Families:
    if fam.Name == 'Family Name':
         # fam is the Family object called 'Family Name', do your worst!
         print fam.Name,'found!'
         print fam.FamilyCategory.Name
Callum
  • 578
  • 3
  • 8