Share

Family.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: 26.1.0.0 (26.1.0.34)

Syntax

C#

public Category FamilyCategory { get; set; }

Property Value

Category

Exceptions

ExceptionCondition
ArgumentException Thrown when the input category cannot be assigned to this family.
ArgumentNullException Thrown when the input category is nullptr.

Remarks

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

Example

C#

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);
}

VB

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

See Also

Reference

Was this information helpful?