2024 Method
Changes 0
M

Categories.NewSubcategory

Description:
Add a new subcategory into the Autodesk Revit document.
public Category NewSubcategory(
	Category parentCategory,
	string name
)
Return Value Category If successful, the newly created subcategory.
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;
}