If you wish to access any information from a Revit Family, be its specific parameter value, category, etc., without opening the family file, you can always load the family and access the information required. However, if have to do this for a number of family files, loading all the families will increase the model file size – that too just for reading a small piece of information. A better approach is to use transactions, load up the family file(s), access the specific family information required (say Family Category) and then roll back the transaction. With rolling back the transaction, it is almost like we never loaded the family to read the information from the Family file. The code below illustrates the complete approach.
using System;
using System.Collections.Generic;
using System.Text;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using Autodesk.Revit.ApplicationServices;
namespace Revit.SDK.Samples.HelloRevit.CS
{
[Transaction(TransactionMode.Manual)]
public class Command : IExternalCommand
{
public Result Execute(ExternalCommandData commandData,
ref string message,
ElementSet elements)
{
Document doc =
commandData.Application.ActiveUIDocument.Document;
Transaction trans = new Transaction(doc, "Open Family");
trans.Start();
Family fam = null;
doc.LoadFamily(@"C:\Users\xyz\Desktop\Sample.rfa", out fam);
TaskDialog.Show("FamilyCategoryName", fam.FamilyCategory.Name);
trans.RollBack();
return Result.Succeeded;
}
}
}