Python - drilling down to all elements in all families

Hi.
This is probably a duplicate post - apologies.
and I am still using version REVIT 2024 (double apology).
In REVIT Families includes:
Structural Framing > BMR -081 14644 > BMR - 081 14644
How do I access the very last BMR - 081 14644 with python?
I guess there’s nesting not accessed in code below - right?
Thx for your patience,
K.

import clr
clr.AddReference("RevitServices")
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import *

doc = DocumentManager.Instance.CurrentDBDocument
categories = doc.Settings.Categories

all_elements = []

for category in categories:
    collector = FilteredElementCollector(doc).OfCategoryId(category.Id)
    elements = collector.ToElements()
    if(len(elements) > 0):
        all_elements.extend(elements)

tset = []
tset.append(["Cat","ID","Ref","Slope","Span","X","Y","Z","Angle"])

for e in all_elements:
    pslope = 0
    pspan = 0
    pref = ""
    pskip = 1
    pnset = []
    for p in e.Parameters:
        if(p.AsString()is None):
            continue
        param_group = p.Definition.ParameterGroup
        param_group_name = LabelUtils.GetLabelFor(param_group).upper()
        if(param_group_name != "IFC PARAMETERS"):
            continue
        if(p.Definition.Name == "Reference"):
            pref = p.AsString()
            pskip = 0
        if("SLOPE" in p.Definition.Name.upper()):
            pslope = p.AsDouble()
        if("SPAN" in p.Definition.Name.upper()):
            pspan = p.AsDouble()
    if pskip == 0:
        loc = e.Location
        lp = None
        lpx = None
        lpy = None
        lpz = None
        lr = None
        if isinstance(loc, LocationPoint):
            lp = loc.Point
            lpx = lp.X
            lpy = lp.Y
            lpz = lp.Z
            lr = loc.Rotation
        elif isinstance(loc, LocationCurve):
            lp = loc.Curve.Evaluate(0.5, True)
            curve = loc.Curve
            direction = curve.GetEndPoint(1) - curve.GetEndPoint(0)
            lr = direction.AngleTo(XYZ(1, 0, 0))
        tset.append([e.Category.Name, e.Id, pref, pslope, pspan, lpx, lpy, lpz, lr])

OUT = tset

a.dyn (10.4 KB)
a.rvt (3.3 MB)
rep.xlsx (10.2 KB)

a.dyn (10.4 KB)
a.rvt (3.3 MB)
rep.xlsx (10.2 KB)

u formatted attachments into code block. :worried:

thx …

symbols = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_StructuralFraming).WhereElementIsElementType().ToElements()

the nesting i assume u mean Family Name → Family Type.

1 Like