Python Help - Family from FamilyType

I’m learning Python for Dynamo. Lynda.com has a good course.

The Python below returns a list of plumbing familytypes.
I know it is easy using a Dynamo node to get the parent family.
Is there a way to do this with python?

import clr

#Import Revit Nodes
clr.AddReference(“RevitNodes”)
import Revit
clr.ImportExtensions(Revit.Elements)

Import RevitAPI

clr.AddReference(“RevitAPI”)
import Autodesk
from Autodesk.Revit.DB import *

Import DocumentManager and TransactionManager

clr.AddReference(“RevitServices”)
from RevitServices.Persistence import DocumentManager

#The inputs to this node will be stored as a list in the IN variables.
doc = DocumentManager.Instance.CurrentDBDocument

#Filtered Element Collector
collector = FilteredElementCollector(doc)

#Quick Filter
filter = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_PlumbingFixtures).FamilyToElements()

#Assign your output to the OUT variable.
OUT = filter

If I’m not mistaken then your code will return all the family instances in the model instead of the family types.
In that case getting the FamilyType and then the Family from a FamilyInstance (from the top of my head) would be something like this:
FamType = instance.FamilySymbol
Family = FamType.Family

Revitapidocs.com is a great site for looking up above information.

Just like @T_Pover said, you’re currently getting family instances. You can filter for family types though, then convert those to families.

import clr
clr.AddReference("RevitNodes")
import Revit
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument

dataEnteringNode = IN
collector = FilteredElementCollector(doc)
collector.OfCategory(BuiltInCategory.OST_PlumbingFixtures)
collector.OfClass(FamilySymbol)
types = collector.ToElements()
families = set()
for type in types:
	families.add(type.Family)
families = list(families)

OUT = families
3 Likes

Thank you Nick
This is creating a list of Families.
I’ve looked at the set() method. I think this should be creating a unique list. The output contains a list that is not unique, it includes the family for each type.

Can you show me what your code looks like?

I think the set() method does not do a true “Equals” comparison and I think that although the Element IDs of the famililes are the same in memory they are not treated as the same objects. So a way to fix this is to compare the IDs instead and feed those into the set() method.
I tried to make it clear in this .dyn: Collect families of category.dyn (6.2 KB)

1 Like

Sorry I didn’t catch that. It just happened to work on my small test file.
Comparing element Ids seems like the way to go @T_Pover.