We created some windows and inserted them into some straight walls at right spots using Revit .NET API and C# before. We did not try round walls yet. In this post, let’s try round walls with the same help methods as introduced before.
Here are the core help methods again.
private static IEnumerable<Family> FindWindowFamilies(RvtDocument doc)
{
return new FilteredElementCollector(doc)
.OfClass(typeof(Family))
.Cast<Family>()
.Where(e => e.FamilyCategory != null
&& e.FamilyCategory.Id.IntegerValue == (int)BuiltInCategory.OST_Windows);
}
public static FamilyInstance InsertWindowAtCenterMiddle(FamilySymbol windowSymbol, Wall wall)
{
LocationCurve locCurve = wall.Location as LocationCurve;
XYZ start = locCurve.Curve.get_EndPoint(0);
XYZ end = locCurve.Curve.get_EndPoint(1);
XYZ location = (start + end) / 2;
FamilyInstance famInst = wall.Document.Create.NewFamilyInstance(location, windowSymbol, wall, wall.Level, StructuralType.NonStructural);
double headHeight = famInst.get_Parameter(BuiltInParameter.INSTANCE_HEAD_HEIGHT_PARAM).AsDouble();
double sillHeight = famInst.get_Parameter(BuiltInParameter.INSTANCE_SILL_HEIGHT_PARAM).AsDouble();
double wallHeight = wall.get_Parameter(BuiltInParameter.WALL_USER_HEIGHT_PARAM).AsDouble();
famInst.get_Parameter(BuiltInParameter.INSTANCE_SILL_HEIGHT_PARAM).Set(wallHeight / 2 - (headHeight - sillHeight) / 2);
return famInst;
}
Here is the round wall creation help method:
public static List<ElementId> CreateRoundWalls(Document doc, Level level, XYZ center, XYZ normal, double radius)
{
List<ElementId> walls = new List<ElementId>();
Arc arc1 = doc.Application.Create.NewArc(new Plane(normal, center), radius, 0, Math.PI);
Arc arc2 = doc.Application.Create.NewArc(new Plane(normal, center), radius, Math.PI, Math.PI * 2);
Wall wall1 = Wall.Create(doc, arc1, level.Id, false);
Wall wall2 = Wall.Create(doc, arc2, level.Id, false);
walls.Add(wall1.Id);
walls.Add(wall2.Id);
return walls;
}
Here is some sample caller code for these help methods.
List<ElementId> wallIDs = WallCreation.CreateRoundWalls(CachedDoc, FindAndSortLevels(CachedDoc).Last(), new XYZ(10, 0, 0), XYZ.BasisZ, 50);
FamilySymbol symbol = DoorWindowOpeningCreation.GetFirstSymbol(DoorWindowOpeningCreation.FindFamilies(CachedDoc, BuiltInCategory.OST_Windows).FirstOrDefault());
foreach (ElementId id in wallIDs)
{
Wall wall = (Wall)CachedDoc.GetElement(id);
try
{
DoorWindowOpeningCreation.InsertWindowAtCenterMiddle(symbol, wall);
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message);
}
}
No exceptions would be thrown out by the above code meaning code is just fine. However, the result is not what we expected. Here is what the windows and the walls look like in Revit.
As can be seen, the windows were all inserted at the start/end ends instead of in the middle of the walls. Obviously something needs to be tuned up in the InsertWindowAtCenterMiddle help method for it to work with round walls as well. We will be doing so next. 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.