ItemFactoryBase.NewFamilyInstance(XYZ, FamilySymbol, Element, StructuralType) Method

ItemFactoryBaseNewFamilyInstance(XYZ, FamilySymbol, Element, StructuralType) Method

Inserts a new instance of a family into the document, using a location, type/symbol, and the host element.

Namespace: Autodesk.Revit.Creation
Assembly: RevitAPI (in RevitAPI.dll) Version: 25.0.0.0 (25.0.0.0)
Syntax
public FamilyInstance NewFamilyInstance(
	XYZ location,
	FamilySymbol symbol,
	Element host,
	StructuralType structuralType
)
Public Function NewFamilyInstance ( 
	location As XYZ,
	symbol As FamilySymbol,
	host As Element,
	structuralType As StructuralType
) As FamilyInstance
public:
FamilyInstance^ NewFamilyInstance(
	XYZ^ location, 
	FamilySymbol^ symbol, 
	Element^ host, 
	StructuralType structuralType
)
member NewFamilyInstance : 
        location : XYZ * 
        symbol : FamilySymbol * 
        host : Element * 
        structuralType : StructuralType -> FamilyInstance 

Parameters

location  XYZ
The physical location where the instance is to be placed.
symbol  FamilySymbol
A FamilySymbol object that represents the type of the instance that is to be inserted.
host  Element
The object into which the FamilyInstance is to be inserted, often known as the host.
structuralType  StructuralType
If structural then specify the type of the component.

Return Value

FamilyInstance
If creation was successful then an instance to the new object is returned, otherwise .
Exceptions
ExceptionCondition
ArgumentExceptionThrown if The symbol is not active.
Remarks
This method is used to insert one family instance into another element, such as inserting a window into a wall. If the instance fails to be created an exception may be thrown.

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.

The host object must be one that supports insertion of instances otherwise this method will fail.

Some Families, such as Beams, have more than one endpoint and are inserted in the same manner as single point instances. Once inserted these linear family instances can have their endpoints changed by using the instance's Element.Location property.

Note: ForbiddenForDynamicUpdateException might be thrown during a dynamic update if the inserted instance establishes a mutual dependency with another structure.

Note: if the created family instance includes nested instances, the API framework will automatically regenerate the document during this method call.

Example
Wall CreateWallWithWindows(Autodesk.Revit.DB.Document document, Level level)
{
    // Create a new wall
    // Build a location line for the wall creation
    XYZ start = new XYZ(0, 0, 0);
    XYZ end = new XYZ(10, 10, 0);
    Line wallLine = Line.CreateBound(start, end);

    // Create a wall using the location line
    Wall newWall = Wall.Create(document, wallLine, level.Id, true);

    // Find a Window type for the new windows
    FilteredElementCollector winCollector = new FilteredElementCollector(document);
    IList<Element> windowTypes = winCollector.OfCategory(BuiltInCategory.OST_Windows).WhereElementIsElementType().ToElements();
    FamilySymbol winType = windowTypes.First() as FamilySymbol;
    // put 3 windows in the wall
    double x = 2, y = 2, z = 2;
    for (int i = 0; i < 3; i++)
    {
        XYZ location = new XYZ(x, y, z);
        FamilyInstance instance = document.Create.NewFamilyInstance(location, winType, newWall, StructuralType.NonStructural);
        x += 3;
        y += 3;
    }

    return newWall;
}
Private Function CreateWallWithWindows(document As Autodesk.Revit.DB.Document, level As Level) As Wall
    ' Create a new wall
    ' Build a location line for the wall creation
    Dim start As New XYZ(0, 0, 0)
    Dim [end] As New XYZ(10, 10, 0)
    Dim wallLine As Line = Line.CreateBound(start, [end])

    ' Create a wall using the location line
    Dim newWall As Wall = Wall.Create(document, wallLine, level.Id, True)

    ' Find a Window type for the new windows
    Dim winCollector As New FilteredElementCollector(document)
    Dim windowTypes As IList(Of Element) = winCollector.OfCategory(BuiltInCategory.OST_Windows).WhereElementIsElementType().ToElements()
    Dim winType As FamilySymbol = TryCast(windowTypes.First(), FamilySymbol)
    ' put 3 windows in the wall
    Dim x As Double = 2, y As Double = 2, z As Double = 2
    For i As Integer = 0 To 2
        Dim location As New XYZ(x, y, z)
        Dim instance As FamilyInstance = document.Create.NewFamilyInstance(location, winType, newWall, StructuralType.NonStructural)
        x += 3
        y += 3
    Next

    Return newWall
End Function

No code example is currently available or this language may not be supported.

No code example is currently available or this language may not be supported.

See Also