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 and create a Metal Clad Column, some such columns along a circle and in a rectangular array.
In this post, let’s load and insert a mass arch programmatically with Revit .NET and C#.
public class MassInsertion
{
public static Family LoadMassFamily(Document doc, string name)
{
string libPath = doc.Application.GetLibraryPaths()["Imperial Library"];
string path = Path.Combine(libPath, @"Mass\" + name + ".rfa");
Family family;
doc.LoadFamily(path, out family);
return family;
}
public static FamilyInstance InsertMass(Document doc, FamilySymbol symbol, Level baseLevel, XYZ location, double rotation)
{
FamilyInstance famInst = doc.Create.NewFamilyInstance(location, symbol, baseLevel, StructuralType.NonStructural);
Line axis = doc.Application.Create.NewLine(location, XYZ.BasisZ, false);
ElementTransformUtils.RotateElement(doc, famInst.Id, axis, rotation);
return famInst;
}
public static FamilyInstance InsertArch(Document doc, Level baseLevel, XYZ location, double rotation)
{
Family family = DoorWindowOpeningCreation.FindFamilies(doc, BuiltInCategory.OST_Mass).FirstOrDefault(e => e.Name == "Arch");
if (family == null)
family = LoadMassFamily(doc, "Arch");
FamilySymbol symbol = ColumnCreation.GetFirstSymbol(family);
return InsertMass(doc, symbol, baseLevel, location, rotation);
}
}
Here is the sample caller code.
ColumnCreation.TestCreateMetalCladColumn(CachedDoc, new XYZ(50, 0, 0));
Level level = FindAndSortLevels(CachedDoc).First();
MassInsertion.InsertArch(CachedDoc, level, new XYZ(50.0, 0, 0), Math.PI / 4);
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.