Retrieving certain family type parameters out of a bunch of *.rfa files
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello and Happy New Year's Eve to all,
I'm trying to make a Revit plugin which basically is a filterable catalog of family files of lighting fixtures. You filter files using some of the parameters and when pick the one you need and load it into the project. But I have a real hard time extracting the parameters out of files. I open families as a document and iterate through every type in the family, retrieving the parameters I need. But for some reason the parameters I retrieve have null values, so all I get when launching the command in Revit is an ArgumentNullException: value cannot be null (screenshot.jpg). But these parameters have values if snoop them using Revit Lookup tool (screenshot2.jpg). Here is the code, maybe I'm missing something, I'll appreciate any insights or help you can provide.
[Transaction(TransactionMode.Manual)]
public class LightingFixture : IExternalCommand
{
Application m_rvtApp;
Document m_rvtDoc;
public Result Execute(ExternalCommandData commandData,
ref string message,
ElementSet elements)
{
UIApplication rvtUIApp = commandData.Application;
UIDocument rvtUIDoc = rvtUIApp.ActiveUIDocument;
m_rvtApp = rvtUIApp.Application;
m_rvtDoc = rvtUIDoc.Document;
string[] filePaths = Directory.GetFiles(@"C:\Users\Admin\Desktop\REVIT_BIM\Revit Family Types", "*.rfa");
List<List<LightingFixtureType>> listOfTypes = new List<List<LightingFixtureType>>();
foreach (string path in filePaths)
{
Document doc = m_rvtApp.OpenDocumentFile(path);
listOfTypes.Add(GetListOfFamilyTypes(doc));
}
foreach (List<LightingFixtureType> types in listOfTypes)
{
TaskDialog.Show("List of Family Types", types.ToString());
}
return Result.Succeeded;
}
public List<LightingFixtureType> GetListOfFamilyTypes(Document familyDoc)
{
if (familyDoc.IsFamilyDocument)
{
FamilyManager familyManager = familyDoc.FamilyManager;
List<LightingFixtureType> list = new List<LightingFixtureType>();
//all these parameters have null values
FamilyParameter familyNameParameter = familyManager.get_Parameter(BuiltInParameter.ALL_MODEL_FAMILY_NAME);
FamilyParameter nameParameter = familyManager.get_Parameter(BuiltInParameter.ALL_MODEL_TYPE_NAME);
FamilyParameter typeParameter = familyManager.get_Parameter(BuiltInParameter.ALL_MODEL_TYPE_COMMENTS);
FamilyParameter loadParameter = familyManager.get_Parameter(BuiltInParameter.RBS_ELEC_APPARENT_LOAD);
FamilyParameter colorParameter = familyManager.get_Parameter(BuiltInParameter.FBX_LIGHT_INITIAL_COLOR_TEMPERATURE);
string familyName = null;
string name = null;
string type = null;
double load = 0;
double colorTemperature = 0;
FamilyTypeSet familyTypes = familyManager.Types;
FamilyTypeSetIterator familyTypesItor = familyTypes.ForwardIterator();
familyTypesItor.Reset();
while (familyTypesItor.MoveNext())
{
FamilyType familyType = familyTypesItor.Current as FamilyType;
familyName = familyType.AsString(familyNameParameter);
name = familyType.AsString(nameParameter);
type = familyType.AsString(typeParameter);
load = (double)familyType.AsDouble(loadParameter);
colorTemperature = (double)familyType.AsDouble(colorParameter);
LightingFixtureType fixture = new LightingFixtureType(familyName, name, type, load, colorTemperature);
list.Add(fixture);
}
return list;
}
return null;
}