Some time ago, I proposed that to maintain consistency in project data, loading families from unknown sources should be prohibited. Only families approved by the administrator and stored in the enterprise family library should be allowed. Therefore, Revit needs to verify the family by checking paths or other relevant information before loading it. Ideally, editing of the family should be restricted, and feedback should be sent to the administrator if the family fails to load. Here, we will first implement a basic self-check function during family loading through secondary development. If possible, we hope to expand this functionality further in the future.
The approach is to utilize the FamilyLoadingIntoDocument event in the Revit API. This event triggers when a family is loaded, allowing us to verify whether the family meets the set criteria. If it does, loading proceeds; otherwise, the family loading transaction is canceled. There are multiple ways to validate the family, but in this example, I check the family’s file path and a specific parameter within the family file. In practical applications, these conditions can be adapted to fit your needs.
Below is the sample code demonstrating this logic:
public class Class1 : IExternalApplication
{
public Result OnStartup(UIControlledApplication application)
{
// Register event handler
application.ControlledApplication.FamilyLoadingIntoDocument += new EventHandler<FamilyLoadingIntoDocumentEventArgs>(CheckFamily);
return Result.Succeeded;
}
public Result OnShutdown(UIControlledApplication application)
{
// Unregister event handler
application.ControlledApplication.FamilyLoadingIntoDocument -= new EventHandler<FamilyLoadingIntoDocumentEventArgs>(CheckFamily);
return Result.Succeeded;
}
private void CheckFamily(object sender, FamilyLoadingIntoDocumentEventArgs e)
{
// Get the storage path of the family
string familyPath = e.FamilyPath;
if (familyPath != @"D:Test")
{
e.Cancel();
TaskDialog.Show("Error", "Loading unaudited families is prohibited. Please contact administrator XXX.");
}
else
{
// Open the family document
Document familyDoc = e.Document.Application.OpenDocumentFile(familyPath + "\" + e.FamilyName + ".rfa");
// Create Family Manager
FamilyManager familyManager = familyDoc.FamilyManager;
// Get current family type
FamilyType familyType = familyManager.CurrentType;
if (familyType == null)
{
familyType = familyManager.NewType("Standard");
}
// Retrieve the parameter
FamilyParameter familyParameter = familyManager.get_Parameter("Test Parameters");
// Validate the parameter
if (familyParameter == null || familyType.AsString(familyParameter) != "Allow loading")
{
if (e.Cancellable)
{
e.Cancel();
TaskDialog.Show("Error", "Loading unaudited families is prohibited. Please contact administrator XXX.");
}
}
familyDoc.Close();
}
}
}













Must log in before commenting!
Sign Up