Sorry, we can’t add a Scope Box subcategory

Starting the week of #AU2023 #Revit API wishes, Peter made a reasonable suggestion that unfortunately can’t be implemented with the Revit API.

“Sub Categories for scope boxes, so I can have different colours, for the different scales, and they can be turned of at the different levels, or the ability to filter them”

The API does support creating sub-categories

var doc = this.ActiveUIDocument.Document;
using (var t = new Transaction(doc, "x"))
{
	t.Start();
	var wallCat = doc.Settings.Categories.Cast<Category>().FirstOrDefault(q => q.Id.IntegerValue == (int)BuiltInCategory.OST_Walls);
	doc.Settings.Categories.NewSubcategory(wallCat, "Wall Subcategory");
	t.Commit();
}

But the restriction preventing creating a Scope Box subcategory does not sit at the level of the Revit UI. It is deeper than that, which we can see by checking “CanAddSubcategory”

or by running this code

var scopeBoxCat = doc.Settings.Categories.Cast<Category>()
	.FirstOrDefault(q => q.Id.IntegerValue == (int)BuiltInCategory.OST_VolumeOfInterest);
using (var t = new Transaction(doc, "x"))
{
	t.Start();		
	doc.Settings.Categories.NewSubcategory(scopeBoxCat, "Scope Box Subcategory");
	t.Commit();
}

which results in a “this category can not add subcategory” exception

So all we can do is vote for this enhancement in the Ideas Forum and wait for Autodesk to remove this limitation.

Leave a comment