How to get the built-in parameter Part type RBS_PART_TYPE of a family?

How to get the built-in parameter Part type RBS_PART_TYPE of a family? this parameter appear in some MEP categories I suppose.

I tried something like that but I do not know how to get it:

part_type_param = family.get_Parameter(BuiltInParameter.RBS_PART_TYPE)
if part_type_param:
    part_type_id = part_type_param.AsElementId()
    if part_type_id != ElementId.InvalidElementId:
        part_type_element = openedDoc.GetElement(part_type_id)
        if part_type_element:
            part_type_value = part_type_element.Name
        else:
            part_type_value = "Element does not exist"
    else:
        part_type_value = "Invalid ElementId"
    familyInfo["PartType"] = part_type_value
else:
    familyInfo["PartType"] = None

EDIT You will need to open the family to access the Part Type FamilyParameter
You can use a FilteredElementCollector and a ParameterFilterRuleFactory to get all elements where the parameter exists and has a value - like this

import clr
import sys

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

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

doc = DocumentManager.Instance.CurrentDBDocument
avid = doc.ActiveView.Id

fec = FilteredElementCollector(doc, avid)
bip = BuiltInParameter.RBS_PART_TYPE
rule = ParameterFilterRuleFactory.CreateHasValueParameterRule(ElementId(bip))
epf = ElementParameterFilter(rule)
OUT = fec.WherePasses(epf).ToElements()

There is also another built in parameter BuiltInParameter.FAMILY_CONTENT_PART_TYPE which might be what you are looking for

2 Likes

After a bit of digging… The part type information is located in the family file (.rfa) Family Class - so you will have to open for each family type you want to access (you could open the family for each instance but that would use more time and computer resources). Here is an example to get the part types for Air Terminals

import clr
import sys

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

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


def get_PartTypeValue(family):
    with doc.EditFamily(family) as famdoc:
        parttypevalue = famdoc.OwnerFamily.get_Parameter(
            BuiltInParameter.FAMILY_CONTENT_PART_TYPE
        ).AsValueString()
        famdoc.Close(False)  # Close without saving
    return parttypevalue


doc = DocumentManager.Instance.CurrentDBDocument

fec = FilteredElementCollector(doc)
families = fec.OfClass(Family).ToElements()
terminals = [f for f in families if f.FamilyCategory.Name == "Air Terminals"]

OUT = [get_PartTypeValue(t) for t in terminals]
2 Likes

Thanks, good examples. The error was just because mistake by using the builtin parameter that appear in the element properties of the project environment but not the builtin parameter of a family which is FAMILY_CONTENT_PART_TYPE, I checked wrong by looking in the Revit API website BuiltInParameter Enumeration.

I resolved it as well by searching a parameter by name “Part Type” but prefer to use built in parameter.