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

Revit .NET Creations API: Create Columns – Rectangular Shape

$
0
0

We created a variety of Revit elements such as walls, windows, doors, openings, floors, roofs, and levels with different shapes such as rectangular and circular if possible programmatically using Revit .NET API and C# before.

In this post, let’s create some architectural rectangular columns.

public static IOrderedEnumerable<Level> FindAndSortLevels(RvtDocument doc)
{
    return new FilteredElementCollector(doc)
                    .WherePasses(new ElementClassFilter(typeof(Level), false))
                    .Cast<Level>()
                    .OrderBy(e => e.Elevation);
}

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

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

public static FamilyInstance InsertColumn(Document doc, XYZ location)
{
    FamilySymbol symbol = GetFirstSymbol(FindColumnFamilies(doc).FirstOrDefault());
    FamilyInstance famInst = doc.Create.NewFamilyInstance(location, symbol, StructuralType.Column);

    return famInst;
}

Here is the sample caller code.

ColumnCreation.InsertColumn(CachedDoc, new XYZ(50, 0, 0));

The architectural rectangular column looks good in Revit.
 RecColumnBad
However, things are not really good. Revit is in an unstable status. As can be seen, its level parameters/properties are empty. If we play around them a bit further, e.g. changing them to some available levels, Revit just crashes at some point.
 RecColumnBadCrashRevit

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