2027 Method
Changes 0
M

ItemFactoryBase.NewFamilyInstance

Description:
Add a line based detail family instance into the Autodesk Revit document, using an line and a view where the instance should be placed.
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.
public FamilyInstance NewFamilyInstance(
	Line line,
	FamilySymbol symbol,
	View specView
)
  • line
    The line location of family instance. The line must in the plane of the view.
  • symbol
    A family symbol object that represents the type of the instance that is to be inserted.
  • specView
    A 2D view in which to display the family instance.
Return Value FamilyInstance FamilyInstance
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);
        }
    }
}