Add a new subcategory into the Autodesk Revit document.
Namespace: Autodesk.Revit.DBAssembly: RevitAPI (in RevitAPI.dll) Version: 26.4.0.0 (26.4.0.0)
Syntax
C#
public Category NewSubcategory(
Category parentCategory,
string name
)
Parameters
- parentCategory Category
- The parent category.
- name String
- The new category name.
Return Value
CategoryIf successful, the newly created subcategory.
Exceptions
| Exception | Condition |
|---|
| ArgumentNullException |
Thrown when the input argument-"parentCategory" or "name"-is null.
|
| 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
C#
public void AssignSubCategory(Document document, GenericForm extrusion)
{
Category cat = document.OwnerFamily.FamilyCategory;
Category subCat = document.Settings.Categories.NewSubcategory(cat, "NewSubCat");
ElementId materialId = Material.Create(document, "Wood Material");
subCat.Material = document.GetElement(materialId) as Material;
extrusion.Subcategory = subCat;
}
VB
Public Sub AssignSubCategory(document As Document, extrusion As GenericForm)
Dim cat As Category = document.OwnerFamily.FamilyCategory
Dim subCat As Category = document.Settings.Categories.NewSubcategory(cat, "NewSubCat")
Dim materialId As ElementId = Material.Create(document, "Wood Material")
subCat.Material = TryCast(document.GetElement(materialId), Material)
extrusion.Subcategory = subCat
End Sub
See Also
Reference