Get a Revit family type from a FamilySymbol, with Python

Hi everyone,

I’m trying to place several instances in a model, using the “doc.Create.NewFamilyInstance()” method.
Hence, I want to narrow my list of family types down to a single type, to be passed as a FamilySymbol parameter.
I do get the Revit family I want, however, the Revit family contains several types and I just can’t boil it down to one of them.

Here’s a snapshot of what works so far:

Would really appreciate some help.

Your fam_sys_lst collector collects all elements of the FamilySymbol class.
There are multiple ways of getting only 1 item:

  • Indexing: e.g. fam_sys_lst[0] would return the first element of that list and is similar to the GetItemAtIndex node of Dynamo.
  • Narrow down your collector: This blog post gives good examples on how to use it.

a Familysymbol is a Type

to filter your collector try this:

filter_typ = [x for x in fam_symb_lst if x.Family.Name == "SP_2D Chair" and Element.Name.GetValue(x) == "40/40"][0]


Great, it worked!

I would like to select the type with a user controlled input, such as type name.
Thanks for the reply and the link, though. I’ll check it out.

Just another little question:
“x.Family.Name” and “Element.Name.GetValue” - are those pure API methods?
I mean, would they work outside of Dynamo environment (Python shell, C# addins and such)?
Thanks again!

x.Family.Name is is the combination of 2 properties (Revit API) Family Property and Name Property (Inherited from [Element ]

Element.Name.GetValue(objet) is a dotnet method PropertyInfo.GetValue Méthode (System.Reflection) | Microsoft Docs to get value from a Property because Dynamo use IronPython
you can also use
__get__ — Python Reference (The Right Way) 0.1 documentation

Note: FamilySymbol.Name does not work due to a IronPython limitation

more info here

1 Like

Great, thanks again!
Indeed, I was struggling with the FamilySymbol.Name method and couldn’t get why it keeps giving me errors.

IndexError: index out of range: 0

Hello, a variant

filter_typ = next((x for x in fam_symb_lst if x.Family.Name == "SP_2D Chair" and Element.Name.GetValue(x) == "40/40"), None)

What is the purpose to digging up this 3-year-old subject without context ? Please Start a new topic in this case.
here is one of the valid reasons why old topics could be automatically closed