This doesn’t quite make sense to me, as elements can contain geometry in multiple sub-categories… Are you after just the geometry of a given sub-category?
I want to know if there are instances of subcategories in the revit documents, so my input would be a list of BUILT-IN subcategories but I get it to work with categories only so I want to expand on this because for exampleI could not get the internal origin, project base point which are under the Category Site. Geometry sounds a joke here
Hi All
You can use lookup node into BriMohareb_2023 package. To get all geometry in the selection element then filter by the subcategory you need. Or use “get geo by subcategory” node in the same package.
Not sure you can do this at project level. My first thinking would be to programatically edit/check/close all loadable families in background and report any that have the object styles present in them of a given name. You could limit by one category given they dont cross categories so wouldnt be too exhaustive.
Hello @GavinCrump I just want to be able to get all elements of built in subcategories by giving their name as input, for example Site - Internal Origin, which built-in category is something like OST_InternalOrigin. I don’t need user created subcategories of loadable families and i don’t need to get any geometry, just any project instance elements with the ID
hello, I tried it and it does what I need, although I think for this case I would need only builtin categories in case of the subcategories in any families placed on the project are identical than other Builtin category.
I resolved partially modifying this part of the code but I cannot get the builtInNames because some of them thay are not builtin, so I get null result based on the code shared above.
AllCategories = doc.Settings.Categories
AllSubCategories = [subcat for cat in doc.Settings.Categories for subcat in cat.SubCategories]
userCategories=[x for n in (AllCategories,AllSubCategories) for x in n]
thank you very much, all working great, I do not want to get all elements, I want to get the categories first, your first answer was quite right and it works, although I would like to filter only the built-in subcategories. Maybe there is a straight forward code to get built-in subcategories?
import sys
import clr
import System
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument
def ElementsByCategory(category, document=doc):
collector = FilteredElementCollector(document).OfCategoryId(category.Id).WhereElementIsNotElementType()
return list(collector)
dictBic = {ElementId(bic) : bic for bic in System.Enum.GetValues(BuiltInCategory)}
allsubCategories = [cat for cat in doc.Settings.Categories if cat.Id in dictBic]
all_Elems_by_SubCategories = sum([ElementsByCategory(subcat) for cat in allsubCategories for subcat in cat.SubCategories], [])
OUT = all_Elems_by_SubCategories