Revit .NET API 2013 has moved the Wall Creation APIs to the Wall class as some static methods. It is nice as related stuffs are put together now. People do not have to dig here and there to find something looking simple and natural anymore.
No sure why Revit .NET still does not allow people to create walls in a more natural way, using the Wall class constructors directly, but it is not the key point in this post. Let’s create round walls here. Here is the sample code first.
public static IOrderedEnumerable<Level> FindAndSortLevels(RvtDocument doc)
{
return new FilteredElementCollector(doc)
.WherePasses(new ElementClassFilter(typeof(Level), false))
.Cast<Level>()
.OrderBy(e => e.Elevation);
}
public void CreateWall_Case4()
{
Arc arc1 = CachedDoc.Application.Create.NewArc(new Plane(new XYZ(0, 0, 1), XYZ.Zero), 10, 0, Math.PI);
Arc arc2 = CachedDoc.Application.Create.NewArc(new Plane(new XYZ(0, 0, 1), XYZ.Zero), 10, Math.PI, Math.PI*2);
List<Curve> arcs = new List<Curve> { arc1, arc2 };
Wall.Create(CachedDoc, arcs, false);
}
The FindAndSortLevels help method has been introduced for some time by earlier posts. Its purpose is to find all Level instances in the Revit document/model either current or not and sort the levels based on their elevation values from the highest to the lowest. In this way, language or cultural factors can be excluded. To find the bottom/ground level is pretty easy and very reliable, getting the last element from the returned list as demonstrated above.
As can be read, we try to construct two circular arcs to form a connected circle and pass the arc list to the Wall.Create method having another signature that accepts a list of Curve as the second argument. It seems natural and most of people may expect ‘done’, however, here is what Revit would say about it.
Autodesk.Revit.Exceptions.InvalidOperationException: Could not construct a proper face with the input curves to create a wall correctly.
at Autodesk.Revit.DB.Wall.Create(Document document, IList`1 profile, Boolean structural)
at RevitNetAPI2013Creations.ExtCmd.CreateWall_Case4() in …
In the coming post, we will be trying another way to create a round wall and work around the API limitation.
Revit Addin Wizard (RevitAddinWizard) provides a variety of 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.