Dear Specialists,
Through ELEMENTEN = UnwrapElement(FilteredElementCollector(doc, ACTIVE_VIEW.Id)).ToElements() i am searching to all elements in active view.
I would like to get the assembly code (Type Parameter) of every item with this rule:
ELEMENTEN_FILTER = []
for PAR in ELEMENTEN:
if hasattr(PAR, "Symbol"):
ELEMENTEN_FILTER.append([PAR, PAR.Symbol.get_Parameter(BuiltInParameter.UNIFORMAT_CODE).AsValueString()])
The problem is not every item have the attributes/methodes get_Parameter + BuiltInParameter + UNIFORMAT_CODE. When i am searching to dir(ELEMENTEN) the list is filled with the standard functions/attributes/methodes.
How to check easy which objects in the list (picture) dont have some methods/attributes?
Split your steps up and make checks where necessary.
- Get the family type.
- Get parameter.
- Get value.
After each step just check for nulls and filter out any failed attempts.
ELEMENTEN_FILTER = []
for PAR in ELEMENTEN:
if hasattr(PAR, "Symbol"):
paramElement = PAR.Symbol.get_Parameter(BuiltInParameter.UNIFORMAT_CODE)
if paramElement:
ELEMENTEN_FILTER.append([PAR, paramElement.AsValueString()])
1 Like
A bit more advanced, however this will get every element in a view which has the type parameter, not just families. Works by collecting all elements with the parameter (whether set or not) then checks if dependent elements (ids) are visible in the selected view and finally getting the elements
import clr
clr.AddReference("RevitServices")
from RevitServices.Persistence import DocumentManager
clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import (
BuiltInParameter,
ElementId,
ElementParameterFilter,
FilteredElementCollector,
LogicalOrFilter,
ParameterFilterRuleFactory,
VisibleInViewFilter,
)
view = IN[0]
doc = DocumentManager.Instance.CurrentDBDocument
pfr_y = ParameterFilterRuleFactory.CreateHasValueParameterRule(
ElementId(BuiltInParameter.UNIFORMAT_CODE)
)
pfr_n = ParameterFilterRuleFactory.CreateHasNoValueParameterRule(
ElementId(BuiltInParameter.UNIFORMAT_CODE)
)
epf_y = ElementParameterFilter(pfr_y)
epf_n = ElementParameterFilter(pfr_n)
lof = LogicalOrFilter(epf_y, epf_n)
vivf = VisibleInViewFilter(doc, ElementId(view.Id))
OUT = filter(
None,
[
[doc.GetElement(id) for id in elem.GetDependentElements(vivf)]
for elem in FilteredElementCollector(doc).WherePasses(lof).ToElements()
],
)
1 Like
Or if you just want the ElementType
or FamilySymbol
to get the parameter use this as the last line of code - for example in the sample HVAC model this will reduce the output from over 2000 elements to 29 for the cover 3D view
OUT = [
elem
for elem in FilteredElementCollector(doc).WherePasses(lof).ToElements()
if elem.GetDependentElements(vivf)
]