Namespace:
Autodesk.Revit.DB
Category
Class
Description:
Represents the category or subcategory to which an element belongs.
Represents the category or subcategory to which an element belongs.
Remarks:
Categories are an import 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.
Categories are an import 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.
Examples
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);