This doesn’t work because you didn’t import “Family”. If you want to access the Family type you need to access the Family type through the DB namespace by using DB.Family. You said it didn’t work even when you used DB.Family, but it works on my end, so you may not have done it properly. I tried both of these and it worked and gave me all the families.
from Autodesk.Revit.DB import Family, FilteredElementCollector
doc = __revit__.ActiveUIDocument.Document
print(FilteredElementCollector(doc).OfClass(Family).ToElements())
from Autodesk.Revit import DB
doc = __revit__.ActiveUIDocument.Document
print(DB.FilteredElementCollector(doc).OfClass(DB.Family).ToElements())
With your original code, if you change the Family to DB.Family it should work.
# this
families = DB.FilteredElementCollector(doc).OfClass(DB.Family).ToElements()
# instead of this
families = DB.FilteredElementCollector(doc).OfClass(Family).ToElements()
You need to prefix everything with DB because you only imported the DB namespace from the Revit Api. Thus, you need to access all the classes through the DB namespace by prefixing everything with “DB.” If you don’t want to prefix you need to import everything individually, like so.
# import like this
from Autodesk.Revit.DB import (FamilySymbol, FilteredElementCollector, ParameterValueProvider, Element,
ElementParameterFilter, FilterElementIdRule, BuiltInParameter)
# instead of like this
from Autodesk.Revit import DB
Edit: You could also import like this if you don’t want to prefix, but it is not recommended because it imports everything in the DB namespace.
from Autodesk.Revit.DB import *
