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

Revit .NET Creations API: Create Columns along Circle/Arc

$
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.

We also created an architectural rectangular column successfully previously. In this post, let’s create some architectural rectangular columns along a circle/arc.

public static List<FamilyInstance> InsertColumnAroundCircle(Document doc, FamilySymbol symbol, Level topLevel, double topOffset, Level baseLevel, double baseOffset, XYZ center, double radius, int num, double startAngle)
{
    List<FamilyInstance> list = new List<FamilyInstance>();

    for (int i = 0; i < num; i++)
    {
        double angle = startAngle *Math.PI/180 + Math.PI * 2/num * i;
        XYZ location = center + new XYZ(radius * Math.Cos(angle), radius * Math.Sin(angle), center.Z);
        FamilyInstance famInst = InsertColumn(doc, symbol,
                                    location,
                                    topLevel, topOffset, baseLevel, baseOffset);
        Line axis = doc.Application.Create.NewLine(location, XYZ.BasisZ, false);
        ElementTransformUtils.RotateElement(doc, famInst.Id, axis, angle);
        list.Add(famInst);
    }

    return list;
}

Here is the sample caller code.

CachedDoc.Application.Create.NewArc(new Plane(XYZ.BasisZ, new XYZ(10.0, 10.0, 0.0)), 10.0, 0.0, Math.PI * 2);
FamilySymbol symbol = ColumnCreation.GetFirstSymbol(ColumnCreation.FindColumnFamilies(CachedDoc).FirstOrDefault());
IOrderedEnumerable<Level> levels = FindAndSortLevels(CachedDoc);
Level toplevel = levels.Last();
Level baseLevel = levels.ElementAt(levels.Count()-2);
ColumnCreation.InsertColumnAroundCircle(CachedDoc,
                                        symbol,
                                        toplevel,
                                        0.0,
                                        baseLevel,
                                        0.0,
                                        new XYZ(10.0, 10.0, 0.0),
                                        10.0,
                                        18,
                                        0.0);

The resultant architectural rectangular columns along the circle both look good and behave in Revit.
 ColumnsAlongCircle

The more beautiful part as can be seen is that each rectangular column is rotated to the proper direction.

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