Revit .NET has provided the family API for several versions. We have been exploring the Revit family .NET API since and presenting many posts along with code examples on this blog.
We demonstrated creating a Torus solid into a family document some time ago in the following article.
Previously, we also demonstrated creating a torus from some profiles defined in another Revit family document rather than creating the sweep profile and path from some arbitrary points and arcs, based on some comments a reader made to the above post.
Khalil also queried if it’s possible to create a sweep along a 3D path. In this article, let’s look into it and see what we will get this time. Obviously, another signature of the NewSweep method has to be used. It accepts a ReferenceArray argument as the sweep path instead of the CurveArray path that we tried a few times before.
FamilyItemFactory.NewSweep Method (Boolean, ReferenceArray, SweepProfile, Int32, ProfilePlaneLocation)
Here we go:
public static List<Element> FindModelCurves(RvtDocument doc)
return new FilteredElementCollector(doc)
.WherePasses(new ElementClassFilter(typeof(CurveElement), false))
public static ElementId CreateTorus3(RvtDocument famDoc, double elevationRadius)
CurveArrArray curveArrArr = new CurveArrArray();
CurveArray curveArr1 = new CurveArray();
Arc arc1 = famDoc.Application.Create.NewArc(XYZ.Zero, elevationRadius, 0.0, Math.PI, XYZ.BasisX, XYZ.BasisY);
Arc arc2 = famDoc.Application.Create.NewArc(XYZ.Zero, elevationRadius, Math.PI, Math.PI * 2, XYZ.BasisX, XYZ.BasisY);
SweepProfile sweepProfile = famDoc.Application.Create.NewCurveLoopsProfile(curveArrArr);
List<Element> curves = FindModelCurves(famDoc);
ReferenceArray refArry = famDoc.Application.Create.NewReferenceArray();
foreach (ModelCurve curve in curves)
Reference reference = new Reference(curve);
Sweep solid = famDoc.FamilyCreate.NewSweep(
ret = solid.Id;
public static void TestCreateTorus3()
RvtDocument famDoc = ExtCmd.CachedDoc;
using (Transaction tr = new Transaction(famDoc, "CreateTorus3"))
Before running the command having the above code incorporated, we need to make sure there are some model lines and arcs and only those in the current family document to form a good single 3D loop, which may look like the following.
Now we run the command. Guess what! The Revit would disappear without any warnings or errors!! Revit .NET API does not crash Revit very often, but we have found such a case now.
So, the conclusion is that Revit .NET Family API is supposed to allow creation of a sweep along a 3d reference path but the reality is impossible. If anything spotted with our code, the 3D reference path being not constructed or retrieved properly, anybody ever creating a sweep along a real 3D path, or any clues, please feel free to jump in here. You will be more than welcome.
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.