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

Revit .NET Creations API: Try to Create a Standalone Door

$
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 standalone door first. 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)
{
    FamilySymbol symbol = GetFirstSymbol(FindDoorFamilies(doc).FirstOrDefault());
    FamilyInstance door = doc.Create.NewFamilyInstance(location, symbol, StructuralType.NonStructural);
           
    return door;
}

Here is some sample caller code:

DoorWindowOpeningCreation.InsertDoor(CachedDoc, XYZ.Zero);

Readers may wonder what the standalone door looks like in Revit. Out of expectations or not, though the door is created (inserted into the current Revit document) successfully judging from the fact that the returned door (FamilyInstance) instance is valid and no errors or exceptions occur at all, the door is not visible in any views. However, the RevitLookup tool will report the door under its FamilyInstance node.

There must be some mystery somewhere. Let’s try to address it in the coming posts. Please stay tuned.

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