Filtering of structural columns...!?

Good morning everyone.
I’m trying to get the STRUCTURAL PILLARS that allow the placement of REINFORCEMENTS…I’m trying to find a way to do it all by PYTHON…
Using Python code.
I only need to capture those “STRUCTURAL PILLARS” that allow me to place “STRUCTURAL REINFORCEMENTS.”
What would be the method or property that allows me to perform this action?


TEST FILTER_ESTRUCTURAL COLUMNS.rvt (2.7 MB)
TEST FILTER_STRUCTURAL COLUMNS.dyn (3.3 KB)

Hi,
you can use this method

import clr
import sys
import System
from System.Collections.Generic import List
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

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

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

doc = DocumentManager.Instance.CurrentDBDocument
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument

filterValidHost = System.Predicate[System.Object](lambda x : RebarHostData.IsValidHost(x))
GeneralColumns = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_StructuralColumns).WhereElementIsNotElementType().ToElements().FindAll(filterValidHost)

OUT = GeneralColumns
1 Like

Hello, in your code, for establishing the filter (filterValidHost), is this class you are using?

Cordially
christian.stan

Yes .Net List can be filtered with FindAll() and a Predicate

alternatively, the use of PLINQ extension remains easily possible with IronPython

import clr
import sys
import System
from System.Collections.Generic import List
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

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

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

doc = DocumentManager.Instance.CurrentDBDocument
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument

clr.AddReference("System.Core")
clr.ImportExtensions(System.Linq)

GeneralColumns = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_StructuralColumns)\
												.WhereElementIsNotElementType()\
												.Where(lambda x : RebarHostData.IsValidHost(x)).ToList()

OUT = GeneralColumns
1 Like

thanks
the filter method you are using is faster in case of a lot of elements, that’s why you are using it?
rather than this

cont=[]

TotalColumns = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_StructuralColumns).WhereElementIsNotElementType().ToElements()

for i in TotalColumns:
    if RebarHostData.IsValidHost(i)==True:
        cont.append(i)
    else:
        pass

OUT = cont,TotalColumns

I have a preference for Predicate and PLINQ extension, but it is not necessarily the fastest methods

there are some tests here

1 Like

Thank you for your always reasoned answers.

Have a good evening
Cordially
christian.stan

1 Like