NewSubcategory Method


Categories New Subcategory Method

Add a new subcategory into the Autodesk Revit document.

Namespace: Autodesk.Revit.DB
Assembly: RevitAPI (in RevitAPI.dll) Version: 25.0.0.0 (25.0.0.0)
Syntax
public Category NewSubcategory(
	Category parentCategory,
	string name
)

Parameters

parentCategory Category
The parent category.
name String
The new category name.

Return Value

Category
If successful, the newly created subcategory.
Exceptions
Exception Condition
ArgumentNullException Thrown when the input argument-"parentCategory" or "name"-is .
ArgumentException Thrown when the input argument-"parentCategory"-cannot add subcategory. Thrown when the input argument-"name"-is an illegal name.
InvalidOperationException Thrown when subcategory creation failed.
Example
public void AssignSubCategory(Document document, GenericForm extrusion)
{
    // create a new subcategory 
    Category cat = document.OwnerFamily.FamilyCategory;
    Category subCat = document.Settings.Categories.NewSubcategory(cat, "NewSubCat");

    // create a new material and assign it to the subcategory
    ElementId materialId = Material.Create(document, "Wood Material");
    subCat.Material = document.GetElement(materialId) as Material;

    // assign the subcategory to the element
    extrusion.Subcategory = subCat;
}
See Also
ArchiLabs Desktop

Put AI to work inside Revit.

Give Desktop your instructions and project files to build Revit families, update model elements, and create views and schedules. Works directly in Revit and AutoCAD.

Explore Desktop →