Get All Elements Of Category

Hi everybody. How can I write the problem of getting the elements of figure 1 as shown in Figure 2. Help me. Thanks

Some thing like that

for cat in cats:
    bic = System.Enum.ToObject(BuiltInCategory, cat.Id.IntegerValue)
    filter =FilteredElementCollector(doc).OfCategory(bic).ToElements()
    ls.append(filter)
OUT = ls
4 Likes


Thank you very much. However, when I try to compose the code like your example, I get an error as shown

Check the library import again, maybe it is not enough.

#Copyright(c) 2021, Hồ Văn Chương
# @chuongmep, https://chuongmep.com/
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Structure import *

clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *

clr.AddReference('System')
from System.Collections.Generic import List

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

import System 
from System.Collections.Generic import *

import sys
sys.path.append(r'C:\Program Files (x86)\IronPython 2.7\Lib')

doc = DocumentManager.Instance.CurrentDBDocument
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = DocumentManager.Instance.CurrentUIApplication.Application

ls = []
cats = doc.Settings.Categories
#Do some action in a Transaction
TransactionManager.Instance.EnsureInTransaction(doc)

for cat in cats:
    bic = System.Enum.ToObject(BuiltInCategory, cat.Id.IntegerValue)
    filter =FilteredElementCollector(doc).OfCategory(bic).ToElements()
    ls.append(filter)
OUT = ls
#Do Action
TransactionManager.Instance.TransactionTaskDone()

OUT = ls

import System
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager

from System.Collections.Generic import List
# Current doc/app/ui
doc = DocumentManager.Instance.CurrentDBDocument

#Filtered element collector 
fram = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_StructuralFraming).WhereElementIsNotElementType().ToElements()


OUT = fram
a = Revit.Category.ByName("StructuralFraming");
ElementQueries.OfCategory(a);
2 Likes