The IFamilyLoadOptions interface of Revit API can be implemented to do something when a family is being loaded into a model, especially to handle cases like family conflict and parameter overwritten.
It provides two methods to be implemented, the OnFamilyFound () and the OnSharedFamilyFound (). The former will be called when the family has already been there and the latter the shared family is found in the model.
Here is a sample implementation in VB.NET:
#Region "Namespaces"
Imports System.Text
Imports System.Linq
Imports System.Xml
Imports System.Reflection
Imports System.ComponentModel
Imports System.Collections
Imports System.Collections.Generic
Imports System.Windows
Imports System.Windows.Media.Imaging
Imports System.Windows.Forms
Imports System.IO
Imports Autodesk.Revit.ApplicationServices
Imports Autodesk.Revit.Attributes
Imports Autodesk.Revit.DB
Imports Autodesk.Revit.DB.Events
Imports Autodesk.Revit.DB.Architecture
Imports Autodesk.Revit.DB.Structure
Imports Autodesk.Revit.DB.Mechanical
Imports Autodesk.Revit.DB.Electrical
Imports Autodesk.Revit.DB.Plumbing
Imports Autodesk.Revit.UI
Imports Autodesk.Revit.UI.Selection
Imports Autodesk.Revit.UI.Events
Imports Autodesk.Revit.Collections
Imports Autodesk.Revit.Exceptions
Imports Autodesk.Revit.Utility
Imports RvtApplication = Autodesk.Revit.ApplicationServices.Application
Imports RvtDocument = Autodesk.Revit.DB.Document
#End Region
Public Class SampleFamilyLoadOptions
Implements IFamilyLoadOptions
#Region "IFamilyLoadOptions Members"
Public Function OnFamilyFound(ByVal familyInUse As Boolean, ByRef overwriteParameterValues As Boolean) As Boolean Implements IFamilyLoadOptions.OnFamilyFound
If Not familyInUse Then
TaskDialog.Show("SampleFamilyLoadOptions", "The family has not been in use and will keep loading.")
overwriteParameterValues = True
Return True
Else
TaskDialog.Show("SampleFamilyLoadOptions", "The family has been in use but will still be loaded with existing parameters overwritten.")
overwriteParameterValues = True
Return True
End If
End Function
Public Function OnSharedFamilyFound(ByVal sharedFamily As Autodesk.Revit.DB.Family, ByVal familyInUse As Boolean, ByRef source As FamilySource, ByRef overwriteParameterValues As Boolean) As Boolean Implements IFamilyLoadOptions.OnSharedFamilyFound
If Not familyInUse Then
TaskDialog.Show("SampleFamilyLoadOptions", "The shared family has not been in use and will keep loading.")
source = FamilySource.Family
overwriteParameterValues = True
Return True
Else
TaskDialog.Show("SampleFamilyLoadOptions", "The shared family has been in use but will still be loaded from the FamilySource with existing parameters overwritten.")
source = FamilySource.Family
overwriteParameterValues = True
Return True
End If
End Function
#End Region
End Class
If the IFamilyLoadOptions implementation is linked with a LoadFamily() method call like the following:
Dim trans As New Autodesk.Revit.DB.Transaction(CachedDoc, "Test LoadFamily with SampleFamilyLoadOptions")
trans.Start()
Dim fam As Autodesk.Revit.DB.Family = Nothing
CachedDoc.LoadFamily("c:/temp/fixed.rfa", New SampleFamilyLoadOptions(), fam)
TaskDialog.Show("Test LoadFamily with SampleFamilyLoadOptions", fam.Name)
trans.Commit()
and the code is called by an external command, the following TaskDialog will appear:
After the TaskDialog is dismissed the family will continue to be loaded with existing parameters overwritten as stated.
Family Optional Loader of RevitAddinWizard can help implement the interface with all possible options and combinations in VB.NET automatically in no time.
Recent Comments