import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
def GetNestedFamilies(fi):
# this allows us to dig down
internalFamilies = []
# add each family to this list to work down
internalFamilies.append(fi)
# for us to output (this can be adapted to be nested further)
nestedList = []
# for us to step through the families
flag = 0
# fwiw, this could also be an int
stopString = "keepGoing"
while stopString == "keepGoing":
if flag != internalFamilies.Count:
#go through all the subcomponents (while adding them to the overall list, to then iterate through)
for subComponent in internalFamilies[flag].GetSubComponentIds():
famDoc = internalFamilies[flag].Document
internalFamily = famDoc.GetElement(subComponent)
# this enables the further digging
internalFamilies.append(internalFamily)
nestedList.append(internalFamily.ToDSType(True))
# increment the flag
flag = flag + 1
stopString = "keepGoing"
else:
stopString = "stahp it"
return nestedList
def tolist(obj1):
if hasattr(obj1,"__iter__"): return obj1
else: return [obj1]
familyInstances = tolist(UnwrapElement(IN[0]))
subLists = []
# iterate through the given instances
for fi in familyInstances:
subLists.append(GetNestedFamilies(fi))
OUT = subLists
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
def get_SubComponent2(item, i = 0):
"""get SubComponents recursively"""
i += 1
if i < 100: # avoid infinite loop
allSub = [item.Document.GetElement(subcompId)for subcompId in item.GetSubComponentIds()]
# return the list and check if SubComponent have a SubComponent too
# use sum trick to flat the python list
return allSub + sum([get_SubComponent2(subitem, i) for subitem in allSub], [])
return []
toList = lambda x : x if hasattr(x, '__iter__') else [x]
lst_item = toList(UnwrapElement(IN[0]))
OUT = [get_SubComponent2(item) for item in lst_item]
@john_pierson@c.poupin Wauw this is awesome what you both did!
Thanks alot for the help, I see someone give the solution already so I don’t have to choose