FamilyCategory Property


Retrieves or sets a Category object that represents the category or sub category in which the elements ( this family could generate ) reside.

Namespace: Autodesk.Revit.DB
Assembly: RevitAPI (in RevitAPI.dll) Version: 24.0.0.0 (24.0.0.0)

Syntax

C#
public Category FamilyCategory { get; set; }
Visual Basic
Public Property FamilyCategory As Category
	Get
	Set
Visual C++
public:
property Category^ FamilyCategory {
	Category^ get ();
	void set (Category^ value);
}

Remarks

All category objects can be retrieved from the application by using the Categories property of the Application.Settings object.

Examples

CopyC#
public void GetBeamAndColumnSymbols(Document document)
{
   List<FamilySymbol> columnTypes = new List<FamilySymbol>();
   List<FamilySymbol> framingTypes = new List<FamilySymbol>();
    FilteredElementCollector collector = new FilteredElementCollector(document);
    ICollection<Element> elements = collector.OfClass(typeof(Family)).ToElements();

    foreach(Element element in elements)
    {
        Family family = element as Family;
        Category category = family.FamilyCategory;
        if (null != category)
        {
            ISet<ElementId> familySymbolIds = family.GetFamilySymbolIds();
            if (BuiltInCategory.OST_StructuralColumns == category.BuiltInCategory)
            {
                foreach (ElementId id in familySymbolIds)
                {
                    FamilySymbol symbol = family.Document.GetElement(id) as FamilySymbol;
                    columnTypes.Add(symbol);
                }
            }
            else if (BuiltInCategory.OST_StructuralFraming == category.BuiltInCategory)
            {
                foreach (ElementId id in familySymbolIds)
                {
                    FamilySymbol symbol = family.Document.GetElement(id) as FamilySymbol;
                    framingTypes.Add(symbol);
                }
            }
        }
    }

    string message = "Column Types: ";
    foreach (FamilySymbol familySymbol in columnTypes)
    {
       message += "\n" + familySymbol.Name;
    }

    TaskDialog.Show("Revit",message);
}
CopyVB.NET
Public Sub GetBeamAndColumnSymbols(document As Document)
   Dim columnTypes As New System.Collections.Generic.List(Of FamilySymbol)
   Dim framingTypes As New System.Collections.Generic.List(Of FamilySymbol)
   Dim collector As New FilteredElementCollector(document)
   Dim elements As ICollection(Of Element) = collector.OfClass(GetType(Family)).ToElements()

   For Each element As Element In elements
      Dim family As Family = TryCast(element, Family)
      Dim category As Category = family.FamilyCategory
      If category IsNot Nothing Then
         Dim familySymbolIds As ISet(Of ElementId) = family.GetFamilySymbolIds()
         If BuiltInCategory.OST_StructuralColumns = category.BuiltInCategory Then
            For Each id As ElementId In familySymbolIds
               Dim symbol As FamilySymbol = TryCast(family.Document.GetElement(id), FamilySymbol)
               columnTypes.Add(symbol)
            Next
         ElseIf BuiltInCategory.OST_StructuralFraming = category.BuiltInCategory Then
            For Each id As ElementId In familySymbolIds
               Dim symbol As FamilySymbol = TryCast(family.Document.GetElement(id), FamilySymbol)
               framingTypes.Add(symbol)
            Next
         End If
      End If
   Next

   Dim message As String = "Column Types: "
   For Each familySybmol As FamilySymbol In columnTypes
      message += vbLf + familySybmol.Name
   Next

   TaskDialog.Show("Revit", message)
End Sub

Exceptions

ExceptionCondition
Autodesk.Revit.ExceptionsArgumentException Thrown when the input category cannot be assigned to this family.
Autodesk.Revit.ExceptionsArgumentNullException Thrown when the input category is a null reference (Nothing in Visual Basic).

See Also

ArchiLabs

Stop fighting Revit automation.

Build repeatable BIM design and documentation workflows with scripts, data, and AI in one place, without wrestling brittle one-off automations.

Try ArchiLabs →