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.
Thanks!

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!
Thanks!

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) https://www.revitapidocs.com/2018.2/14272fe6-5fc3-f053-b4c6-2f44d05786f2.htm and https://www.revitapidocs.com/2018.2/e372092e-ff47-71c2-1272-50ab08e5a41d.htm (Inherited from [Element ]

Element.Name.GetValue(objet) is a dotnet method https://docs.microsoft.com/fr-fr/dotnet/api/system.reflection.propertyinfo.getvalue?view=netframework-4.8 to get value from a Property because Dynamo use IronPython
you can also use
Element.Name.__get__(objet)
https://python-reference.readthedocs.io/en/latest/docs/dunderdsc/get.html

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

more info here

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