This Revit Macro will get the subcategory of a reference plane.
public void GetCat()
{
//find a subcategory of reference planes by name
UIDocument uidoc = ActiveUIDocument;
Document doc = ActiveUIDocument.Document;
Autodesk.Revit.DB.View pView = ActiveUIDocument.Document.ActiveView;
Selection selection = uidoc.Selection;
ICollection<ElementId> selectedIds = uidoc.Selection.GetElementIds();
//test example code for lines;
/*
Categories cats = doc.Settings.Categories;
Category lineCat = null;
foreach (Category cat in cats)
{
if (cat.Id.IntegerValue == -2000530)
{
lineCat = cat;
break;
}
}
if (lineCat != null)
{
foreach (Category subCat in lineCat.SubCategories)
{
if (revitFamily.FamilyName == "Model Lines")
types.Add(subCat.Name);
else if (revitFamily.FamilyName == "Detail Lines" && !subCat.Name.StartsWith("<") && !subCat.Name.EndsWith(">"))
types.Add(subCat.Name);
}
}
*/
//Earlier attempt to find the subcategories and to add one and change the color
//filter to find the subcategories
//ElementCategoryFilter filter = new ElementCategoryFilter(BuiltInCategory.OST_CLines);
//
//FilteredElementCollector collector = new FilteredElementCollector(doc);
//IList<Element> subcats = collector.WherePasses(filter).WhereElementIsNotElementType().ToElements();
//String prompt = "The subcategories in the current document are:\n";
//foreach (Element e in subcats)
// {
//ElementId id = e.Id;
// Category cat = e.Category;
// prompt += e.Name + " " + cat.Name.ToString() + "\n";
// }
// TaskDialog.Show("Revit", prompt);
///THIS WORKS FOR GETTING ITEM SUBCATEGORIES
Category refCat = doc.Settings.Categories.get_Item(BuiltInCategory.OST_CLines);
CategoryNameMap subcats = refCat.SubCategories;
Category myCat = subcats.get_Item("TopPlane Subcategory");
if (myCat != null)
{
TaskDialog.Show ("Found TopPlane Subcategory", myCat.Name.ToString ());
TaskDialog.Show("Element ID", myCat.Id.ToString ());
}
else
{
TaskDialog.Show("Did not find subcategory", "So Sad :(");
}
//Category refsubCat;
//string newSubCatName = "Test Create Ref Subcat";
//Color newSubCatColor = new Color(255, 0, 0); //Red
//try
//{
//using (Transaction docTransaction = new Transaction(doc, "ref planes SubCategory"))
//{
//docTransaction.Start();
//refsubCat = doc.Settings.Categories.NewSubcategory(refCat, newSubCatName);
//refsubCat.LineColor = newSubCatColor;
//docTransaction.Commit();
//}
//}
//catch (Exception ex)
//{
//MessageBox.Show(ex.ToString());
//}
}