2024 Method
Changes 4
M

ItemFactoryBase.NewFamilyInstance

Description:
Inserts a new instance of a family onto a face referenced by the input Reference instance, using a location, reference direction, and a type/symbol.
Remarks:
Use this method to insert one family instance on a face of another element, using a point on the face and a vector to define the position and direction of the new symbol.

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 support insertion of instances, otherwise this method will fail. If the instances fails to be created an exception may be thrown.

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: if the created family instance includes nested instances, the API framework will automatically regenerate the document during this method call.

public FamilyInstance NewFamilyInstance(
	Reference reference,
	XYZ location,
	XYZ referenceDirection,
	FamilySymbol symbol
)
Return Value nullNothingnullptr An instance of the new object if creation was successful, otherwise null Nothing nullptr a null reference ( Nothing in Visual Basic) .
void CreateNurseCallDomeOnWall(Autodesk.Revit.DB.Document document, Wall wall)
{
    FilteredElementCollector collector = new FilteredElementCollector(document);
    collector.OfClass(typeof(FamilySymbol)).OfCategory(BuiltInCategory.OST_NurseCallDevices);

    FamilySymbol symbol = collector.FirstElement() as FamilySymbol;

    // Get interior face of wall
    IList<Reference> sideFaces = HostObjectUtils.GetSideFaces(wall, ShellLayerType.Interior);
    Reference interiorFaceRef = sideFaces[0];

    XYZ location = new XYZ(4, 2, 8);
    XYZ refDir = new XYZ(0, 0, 1);

    FamilyInstance instance = document.Create.NewFamilyInstance(interiorFaceRef, location, refDir, symbol);
}