NewFamilyInstance Method (Line, FamilySymbol, View)


Add a line based detail family instance into the Autodesk Revit document, using an line and a view where the instance should be placed.

Namespace: Autodesk.Revit.Creation
Assembly: RevitAPI (in RevitAPI.dll) Version: 2015.0.0.0 (2015.0.0.0)

Syntax

C#
public FamilyInstance NewFamilyInstance(
	Line line,
	FamilySymbol symbol,
	View specView
)
Visual Basic
Public Function NewFamilyInstance ( _
	line As Line, _
	symbol As FamilySymbol, _
	specView As View _
) As FamilyInstance
Visual C++
public:
FamilyInstance^ NewFamilyInstance(
	Line^ line, 
	FamilySymbol^ symbol, 
	View^ specView
)

Parameters

line
Type: Autodesk.Revit.DB Line
The line location of family instance. The line must in the plane of the view.
symbol
Type: Autodesk.Revit.DB FamilySymbol
A family symbol object that represents the type of the instance that is to be inserted.
specView
Type: Autodesk.Revit.DB View
A 2D view in which to display the family instance.

Remarks

This overload applies only to 2D family line based detail symbols. The type/symbol that is used must be loaded into the document before this method is called. Families and their symbols can be loaded using the Document.LoadFamily or Document.LoadFamilySymbol methods.

Examples

Copy C#
void CreateDetailComponent(Autodesk.Revit.DB.Document document, View view)
{
    // Create a detail component in the given view if it is a detail or drafting view
    if (view.ViewType == ViewType.Detail ||
        view.ViewType == ViewType.DraftingView)
    {
        FamilySymbol symbol = null;
        FilteredElementCollector fsCollector = new FilteredElementCollector(document);
        fsCollector.OfClass(typeof(FamilySymbol)).OfCategory(BuiltInCategory.OST_DetailComponents);
        ICollection<Element> collection = fsCollector.ToElements();
        foreach (Element element in collection)
        {
            FamilySymbol current = element as FamilySymbol;
            // This NewFamilyInstance overload requires a curve based family
            if (current.Family.FamilyPlacementType == FamilyPlacementType.CurveBasedDetail)
            {
                symbol = current;
                break;
            }
        }

        if (symbol != null)
        {
            // create a 2' detail component at the view's origin
            XYZ start = view.Origin;
            XYZ end = start + new XYZ(2, 0, 0);

            Line line = Line.CreateBound(start, end);

            FamilyInstance instance = document.Create.NewFamilyInstance(line, symbol, view);
        }
    }
}
Copy VB.NET
Private Sub CreateDetailComponent(document As Autodesk.Revit.DB.Document, view As View)
    ' Create a detail component in the given view if it is a detail or drafting view
    If view.ViewType = ViewType.Detail OrElse view.ViewType = ViewType.DraftingView Then
        Dim symbol As FamilySymbol = Nothing
        Dim fsCollector As New FilteredElementCollector(document)
        fsCollector.OfClass(GetType(FamilySymbol)).OfCategory(BuiltInCategory.OST_DetailComponents)
        Dim collection As ICollection(Of Element) = fsCollector.ToElements()
        For Each element As Element In collection
            Dim current As FamilySymbol = TryCast(element, FamilySymbol)
            ' This NewFamilyInstance overload requires a curve based family
            If current.Family.FamilyPlacementType = FamilyPlacementType.CurveBasedDetail Then
                symbol = current
                Exit For
            End If
        Next

        If symbol IsNot Nothing Then
            ' create a 2' detail component at the view's origin
            Dim start As XYZ = view.Origin
            Dim [end] As XYZ = start + New XYZ(2, 0, 0)

            Dim line__1 As Line = Line.CreateBound(start, [end])

            Dim instance As FamilyInstance = document.Create.NewFamilyInstance(line__1, symbol, view)
        End If
    End If
End Sub

Exceptions

Exception Condition
Autodesk.Revit.Exceptions ArgumentNullException Thrown when input argument line or symbol or specView is a null reference ( Nothing in Visual Basic) .
Autodesk.Revit.Exceptions ArgumentException Thrown when input argument line or symbol or specView is invalid, or cannot make such type in the specView, or the line is not in the plane of specView.
Autodesk.Revit.Exceptions InvalidOperationException Thrown when failed to create the instance.
Autodesk.Revit.Exceptions InvalidOperationException Thrown when attempting to place a model-based family. Only 2D detail families can be placed in views.

See Also