EditFamily Method


Gets the document of a loaded family to edit.

Namespace: Autodesk.Revit.DB
Assembly: RevitAPI (in RevitAPI.dll) Version: 24.0.0.0 (24.0.0.0)

Syntax

C#
public Document EditFamily(
	Family loadedFamily
)
Visual Basic
Public Function EditFamily ( _
	loadedFamily As Family _
) As Document
Visual C++
public:
Document^ EditFamily(
	Family^ loadedFamily
)

Parameters

loadedFamily
Type: Autodesk.Revit.DBFamily
The loaded family in current document.

Return Value

Reference of the document of the family.

Remarks

This creates an independent copy of the family for editing. To apply the changes back to the family stored in the document, use the LoadFamily overload accepting IFamilyLoadOptions.

This method may not be called if the document is currently modifiable (has an open transaction) or is in a read-only state. The method may not be called during dynamic updates. To test the document's current status, check the values of IsModifiable and IsReadOnly properties.

Examples

CopyC#
public void GetLoadedSymbols(Autodesk.Revit.DB.Document document, FamilyInstance familyInstance)
{
    if (null != familyInstance.Symbol)
    {
        // Get family associated with this
        Family family = familyInstance.Symbol.Family;

        // Get Family document for family
        Document familyDoc = document.EditFamily(family);
        if (null != familyDoc && familyDoc.IsFamilyDocument == true)
        {
            String loadedFamilies = "FamilySymbols in " + family.Name + ":\n";
            FilteredElementCollector collector = new FilteredElementCollector(document);
            ICollection<Element> collection = 
                collector.OfClass(typeof(FamilySymbol)).ToElements();
            foreach (Element e in collection)
            {
                FamilySymbol fs = e as FamilySymbol;
                loadedFamilies += "\t" + fs.Name + "\n";
            }

            TaskDialog.Show("Revit",loadedFamilies);
        }
    }
}
CopyVB.NET
Public Sub GetLoadedSymbols(document As Autodesk.Revit.DB.Document, familyInstance As FamilyInstance)
    If familyInstance.Symbol IsNot Nothing Then
        ' Get family associated with this
        Dim family As Family = familyInstance.Symbol.Family

        ' Get Family document for family
        Dim familyDoc As Document = document.EditFamily(family)
        If familyDoc IsNot Nothing AndAlso familyDoc.IsFamilyDocument = True Then
            Dim loadedFamilies As [String] = "FamilySymbols in " + family.Name & ":" & vbLf
            Dim collector As New FilteredElementCollector(document)
            Dim collection As ICollection(Of Element) = collector.OfClass(GetType(FamilySymbol)).ToElements()
            For Each e As Element In collection
                Dim fs As FamilySymbol = TryCast(e, FamilySymbol)
                loadedFamilies += vbTab + fs.Name & vbLf
            Next

            TaskDialog.Show("Revit", loadedFamilies)
        End If
    End If
End Sub

Exceptions

ExceptionCondition
Autodesk.Revit.ExceptionsArgumentNullException Thrown when the input argument-"loadedFamily"-is a null reference (Nothing in Visual Basic).
Autodesk.Revit.ExceptionsArgumentException Thrown when the input argument-"loadedFamily"-is an in-place family or a non-editable family. (This can be checked with the IsInPlace and IsEditable properties of the Family class.
Autodesk.Revit.ExceptionsInvalidOperationException Thrown when the family is already being edited.
Autodesk.Revit.ExceptionsForbiddenForDynamicUpdateException Thrown if this method is called during dynamic update.
Autodesk.Revit.ExceptionsInvalidOperationException Thrown if this method is called while the document is modifiable (i.e. it has an unfinished transaction.)
Autodesk.Revit.ExceptionsInvalidOperationException Thrown if this method is currently in a read-only state.

See Also