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.
We created an architectural rectangular column successfully, arranged some such columns along a circle/arc and in a rectangular array before. We also managed to load a column family dynamically into the current document previously. In this post, let’s create a Metal Clad Column and load its type if not yet into the current document before the creation.
public static Family LoadColumnFamily(Document doc, string name)
{
string libPath = doc.Application.GetLibraryPaths()["Imperial Library"];
string path = Path.Combine(libPath, @"Columns\" + name + ".rfa");
Family family;
doc.LoadFamily(path, out family);
return family;
}
public static FamilyInstance InsertMetalCladColumn(Document doc, XYZ location, Level topLevel, double topOffset, Level baseLevel, double baseOffset)
{
Family family = ColumnCreation.FindColumnFamilies(doc).FirstOrDefault(e => e.Name == "Metal Clad Column");
if (family == null )
family = LoadColumnFamily(doc, "Metal Clad Column");
FamilySymbol symbol = ColumnCreation.GetFirstSymbol(family);
return InsertColumn(doc, symbol, location, topLevel, topOffset, baseLevel, baseOffset);
}
public static void TestCreateMetalCladColumn(Document doc, XYZ location)
{
FamilySymbol symbol = ColumnCreation.GetFirstSymbol(ColumnCreation.FindColumnFamilies(doc).FirstOrDefault());
IOrderedEnumerable<Level> levels = FindAndSortLevels(doc);
Level toplevel = levels.Last();
Level baseLevel = levels.ElementAt(levels.Count() - 2);
InsertMetalCladColumn(doc, location, toplevel, -2.0, baseLevel, 2.0);
}
Here is the sample caller code.
ColumnCreation.TestCreateMetalCladColumn(CachedDoc, new XYZ(50, 0, 0));
Here is how it looks like in Revit.
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.