Python Help - Family from FamilyType

I’m learning Python for Dynamo. 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
import Revit

Import RevitAPI

import Autodesk
from Autodesk.Revit.DB import *

Import DocumentManager and TransactionManager

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 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
import Revit
from Autodesk.Revit.DB import *
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument

dataEnteringNode = IN
collector = FilteredElementCollector(doc)
types = collector.ToElements()
families = set()
for type in types:
families = list(families)

OUT = families

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.