Category Class

Category Class

Represents the category or subcategory to which an element belongs.
Inheritance Hierarchy
SystemObject
  Autodesk.Revit.DBAPIObject
    Autodesk.Revit.DBCategory

Namespace: Autodesk.Revit.DB
Assembly: RevitAPI (in RevitAPI.dll) Version: 25.0.0.0 (25.0.0.0)
Syntax
public class Category : APIObject
Public Class Category
	Inherits APIObject
public ref class Category : public APIObject
type Category = 
    class
        inherit APIObject
    end

The Category type exposes the following members.

Properties
 NameDescription
Public propertyAllowsBoundParameters To check if the category can have project parameters.
Public propertyAllowsVisibilityControlWhether the visibility can be controlled by the user for this category in this view.
Public propertyBuiltInCategory Gets the BuiltInCategory value for this category.
Public propertyCanAddSubcategoryIndicates if subcategories can be assigned to the category.
Public propertyCategoryType Gets the category type of this category.
Public propertyHasMaterialQuantities Identifies if elements of the category are able to report what materials they contain in what quantities.
Public propertyId Returns the category id associated with the category object.
Public propertyIsCuttableIndicates if the category is cuttable or not.
Public propertyCode exampleIsReadOnlyIdentifies if the object is read-only or modifiable.
(Inherited from APIObject)
Public propertyIsTagCategory Identifies if the category is associated with a type of tag for a different category.
Public propertyIsValidIndicates if the Category is valid or not.
Public propertyIsVisibleInUI Identifies if the category is visible to the user and should be displayed in UI.
Public propertyLineColorThe color of lines shown for elements of this category.
Public propertyMaterial Retrieves or changes the material of the category.
Public propertyNameThe category name.
Public propertyParentReturns the parent category of this category.
Public propertySubCategoriesReturns a map containing all of the subcategories of this category.
Public propertyVisible Retrieves or changes the visibility of the category in the active view.
Top
Methods
 NameDescription
Public methodDisposeCauses the object to release immediately any resources it may be utilizing.
(Inherited from APIObject)
Public methodEqualsDetermines whether the specified object is equal to the current object.
(Inherited from Object)
Public methodStatic memberGetBuiltInCategory Gets the BuiltInCategory value corresponding to the given built-in category identifier.
Public methodStatic memberGetBuiltInCategoryTypeId Gets the ForgeTypeId identifying the given built-in category.
Public methodStatic memberGetCategory(Document, BuiltInCategory)Retrieves a category object corresponding to a BuiltInCategory id.
Public methodStatic memberGetCategory(Document, ElementId) Retrieves a category object corresponding to the category id.
Public methodGetGraphicsStyleGets the graphics style associated with this category for the given graphics style type.
Public methodGetHashCode
(Overrides ObjectGetHashCode)
Public methodGetLinePatternIdGets the line pattern id associated with this category for the given graphics style type.
Public methodGetLineWeightRetrieves the line weight assigned to the category for the given graphics style type.
Public methodGetTypeGets the Type of the current instance.
(Inherited from Object)
Public methodStatic memberIsBuiltInCategory Checks whether a ForgeTypeId identifies a built-in category.
Public methodStatic memberIsBuiltInCategoryValid Checks if a Category exists for a given BuiltInCategory.
Public methodSetLinePatternIdSets the line pattern id associated with this category for the given graphics style type.
Public methodSetLineWeightSets the line weight for the given graphics style type.
Public methodToStringReturns a string that represents the current object.
(Inherited from Object)
Top
Remarks
Categories are an important tool within Revit for identifying the inferred type of an element, such as anything in the Walls category should be considered as a wall. The API exposes access to the built in categories within Revit via the Document.Settings.Categories property.
Example
Element selectedElement = null;
foreach (ElementId id in uidoc.Selection.GetElementIds())
{
    selectedElement = document.GetElement(id);
    break;  // just get one selected element
}

// Get the category instance from the Category property
Category category = selectedElement.Category;

BuiltInCategory enumCategory = category.BuiltInCategory;

// Format the prompt string, which contains the category information
String prompt = "The category information of the selected element is: ";
prompt += "\n\tName:\t" + category.Name;   // Name information

prompt += "\n\tId:\t" + enumCategory.ToString();    // Id information
prompt += "\n\tParent:\t";
if (null == category.Parent)
{
    prompt += "No Parent Category";   // Parent information, it may be null
}
else
{
    prompt += category.Parent.Name;
}

prompt += "\n\tSubCategories:"; // SubCategories information, 
CategoryNameMap subCategories = category.SubCategories;
if (null == subCategories || 0 == subCategories.Size) // It may be null or has no item in it
{
    prompt += "No SubCategories;";
}
else
{
    foreach (Category ii in subCategories)
    {
        prompt += "\n\t\t" + ii.Name;
    }
}

// Give the user some information
TaskDialog.Show("Revit",prompt);
Dim selectedElement As Element = Nothing
For Each id As ElementId In uidoc.Selection.GetElementIds()
    selectedElement = document.GetElement(id)
    ' just get one selected element
    Exit For
Next

' Get the category instance from the Category property
Dim category As Category = selectedElement.Category

Dim enumCategory As BuiltInCategory = category.BuiltInCategory

' Format the prompt string, which contains the category information
Dim prompt As [String] = "The category information of the selected element is: "
prompt += vbLf & vbTab & "Name:" & vbTab + category.Name
' Name information
prompt += vbLf & vbTab & "Id:" & vbTab & enumCategory.ToString()
' Id information
prompt += vbLf & vbTab & "Parent:" & vbTab
If category.Parent Is Nothing Then
    ' Parent information, it may be null
    prompt += "No Parent Category"
Else
    prompt += category.Parent.Name
End If

prompt += vbLf & vbTab & "SubCategories:"
' SubCategories information, 
Dim subCategories As CategoryNameMap = category.SubCategories
If subCategories Is Nothing OrElse 0 = subCategories.Size Then
    ' It may be null or has no item in it
    prompt += "No SubCategories;"
Else
    For Each ii As Category In subCategories
        prompt += vbLf & vbTab & vbTab + ii.Name
    Next
End If

' Give the user some information
TaskDialog.Show("Revit", prompt)

No code example is currently available or this language may not be supported.

No code example is currently available or this language may not be supported.

See Also