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

Revit .NET Creations API: Insert a Door into Wall - Pt. 1

$
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 wall and insert it into a wall. 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 InsertDoor(Document doc, XYZ location, Element host)
{
    FamilySymbol symbol = GetFirstSymbol(FindDoorFamilies(doc).FirstOrDefault());
    //FamilyInstance door = doc.Create.NewFamilyInstance(location, symbol, host, StructuralType.NonStructural);
    FamilyInstance door = doc.Create.NewFamilyInstance(location, symbol, host, host.Level, StructuralType.NonStructural);

    return door;
}

As can be seen, this time, another signature of the Document.Create.NewFamilyInstance method is used so that we can set up the relationship between the door and the wall. However, one odd thing is that if another signature, as commented out in the code, which does not have the Level parameter, were used, the following exception would come up no matter whatever adjustments were made to the wall or the door.

“Can't cut instance of 36" x 84" out of Wall.”

Here is some sample caller code.

Line line = CachedDoc.Application.Create.NewLineBound(new XYZ(10, 0, 0), new XYZ(25, 0, 0));
Element wall = Wall.Create(CachedDoc, line, FindAndSortLevels(CachedDoc).Last().Id, false);
DoorWindowOpeningCreation.InsertDoor(CachedDoc, new XYZ(15, 0, 10), wall);

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

DoorInWall

From the code, it seems we can reach the conclusion that the location of the door is not relative to its host wall but is an absolute coordinate. However, this theory can only prove the distance from the left side of the door to the start edge of the wall, 5’ here. The position of the door along the wall vertical direction (the Z axis) cannot agree with the 10’ that is provided in the call to the NewFamilyInstance method. We would expect to see that the door has a Sill Height of 3’ which makes the position along Z is indeed 10’, but we had to be disappointed.

In the coming posts, we will be addressing this issue and inserting more doors flexibly into walls.

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