Category
Represents the category or subcategory to which an element belongs.
Inheritance Hierarchy
System.Object
Autodesk.Revit.DB.APIObject
Autodesk.Revit.DB.Category
Namespace: Autodesk.Revit.DB
Assembly: RevitAPI (in RevitAPI.dll) Version: 25.0.0.0 (25.0.0.0)
Syntax
public class Category : APIObject
The Category type exposes the following members.
Properties
Name
Description
Public Property
AllowsBoundParameters
To check if the category can have project parameters.
Public Property
AllowsVisibilityControl
Whether the visibility can be controlled by the user for this category in this view.
Public Property
BuiltInCategory
Gets the
BuiltInCategory
value for this category.Public Property
CanAddSubcategory
Indicates if subcategories can be assigned to the category.
Public Property
CategoryType
Gets the category type of this category.
Public Property
HasMaterialQuantities
Identifies if elements of the category are able to report what materials they contain in what quantities.
Public Property
Id
Returns the category id associated with the category object.
Public Property
IsCuttable
Indicates if the category is cuttable or not.
Public Property
Code Example
IsReadOnly
Identifies if the object is read-only or modifiable.
(Inherited from APIObject)
Public Property
IsTagCategory
Identifies if the category is associated with a type of tag for a different category.
Public Property
IsValid
Indicates if the Category is valid or not.
Public Property
IsVisibleInUI
Identifies if the category is visible to the user and should be displayed in UI.
Public Property
LineColor
The color of lines shown for elements of this category.
Public Property
Material
Retrieves or changes the material of the category.
Public Property
Name
The category name.
Public Property
Parent
Returns the parent category of this category.
Public Property
SubCategories
Returns a map containing all of the subcategories of this category.
Public Property
Visible
Retrieves or changes the visibility of the category in the active view.
Methods
Name
Description
Public Method
Dispose
Causes the object to release immediately any resources it may be utilizing.
(Inherited from APIObject)
Public Method
Equals
Determines whether the specified object is equal to the current object.
(Inherited from Object)
Public Method
Static Member
GetBuiltInCategory
Gets the BuiltInCategory value corresponding to the given built-in category identifier.
Public Method
Static Member
GetBuiltInCategoryTypeId
Gets the ForgeTypeId identifying the given built-in category.
Public Method
Static Member
GetCategory(Document, BuiltInCategory)
Retrieves a category object corresponding to a BuiltInCategory id.
Public Method
Static Member
GetCategory(Document, ElementId)
Retrieves a category object corresponding to the category id.
Public Method
GetGraphicsStyle
Gets the graphics style associated with this category for the given graphics style type.
Public Method
GetHashCode
(Overrides Object.GetHashCode.)
Public Method
GetLinePatternId
Gets the line pattern id associated with this category for the given graphics style type.
Public Method
GetLineWeight
Retrieves the line weight assigned to the category for the given graphics style type.
Public Method
GetType
Gets the Type of the current instance.
(Inherited from Object)
Public Method
Static Member
IsBuiltInCategory
Checks whether a ForgeTypeId identifies a built-in category.
Public Method
Static Member
IsBuiltInCategoryValid
Checks if a Category exists for a given BuiltInCategory.
Public Method
SetLinePatternId
Sets the line pattern id associated with this category for the given graphics style type.
Public Method
SetLineWeight
Sets the line weight for the given graphics style type.
Public Method
ToString
Returns a string that represents the current object.
(Inherited from Object)
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 propertyCategory category = selectedElement.Category;
BuiltInCategory enumCategory = category.BuiltInCategory;
// Format the prompt string, which contains the category informationString prompt = "The category information of the selected element is: ";prompt += "\n\tName:\t" + category.Name; // Name information
prompt += "\n\tId:\t" + enumCategory.ToString(); // Id informationprompt += "\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 informationTaskDialog.Show("Revit",prompt);