Quantcast
Channel: RevitNetAddinWizard & NavisworksNetAddinWizard
Viewing all articles
Browse latest Browse all 872

Revit .NET Creations API: Insert a Door into Wall - Pt. 3 (At Bottom Middle of the Wall)

$
0
0

In Revit .NET API 2013, though the NewWall method has been moved to the Wall class itself, the FamilyInstance generation method has not. It is still in the Document.Create instance. Anyway, we figured where it is and were able to create some FamilyInstance objects such as Doors.

In this article, let’s create a door and insert it into a wall at its center along Z and bottom along X. Here are the core help methods.

private static IEnumerable<Family> FindDoorFamilies(RvtDocument doc)
{
    return new FilteredElementCollector(doc)
        .OfClass(typeof(Family))
        .Cast<Family>()
        .Where(e => e.FamilyCategory != null
                && e.FamilyCategory.Id.IntegerValue == (int)BuiltInCategory.OST_Doors);
}

private static FamilySymbol GetFirstSymbol(Family family)
{
    return (from FamilySymbol fs in family.Symbols select fs).FirstOrDefault();
}

public static FamilyInstance InsertDoorAtBottomMiddle(FamilySymbol windowSymbol, Wall wall)
{
    LocationCurve locCurve = wall.Location as LocationCurve;
    XYZ start = locCurve.Curve.get_EndPoint(0);
    XYZ end = locCurve.Curve.get_EndPoint(1);
    XYZ location = (start + end) / 2;

    FamilyInstance famInst = wall.Document.Create.NewFamilyInstance(location, windowSymbol, wall, wall.Level, StructuralType.NonStructural);
    famInst.get_Parameter(BuiltInParameter.INSTANCE_SILL_HEIGHT_PARAM).Set(0);

    return famInst;
}

Here is some sample caller code.

Line line = CachedDoc.Application.Create.NewLineBound(new XYZ(50, 0, 0), new XYZ(65, 0, 0));
Wall wall = Wall.Create(CachedDoc, line, FindAndSortLevels(CachedDoc).Last().Id, false);
FamilySymbol symbol = DoorWindowOpeningCreation.GetFirstSymbol(DoorWindowOpeningCreation.FindDoorFamilies(CachedDoc).FirstOrDefault());
DoorWindowOpeningCreation.InsertWindowAtCenterMiddle(symbol, wall);

Here is what the door and the wall look like in Revit.

DoorInWall3
As can be seen, the door is inserted into the wall at the right relative spot, center along the horizontal direction and bottom along vertical.

Revit Addin Wizard (RevitAddinWizard) provides various wizards, coders and widgets to help program Revit addins. It can be downloaded from the Download link at the bottom of the blog index page.


Viewing all articles
Browse latest Browse all 872

Trending Articles