Revit .NET has provided the family API for several versions. We have been exploring the Revit family .NET API 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.
Revit Family .NET API: Create Torus in Family Document
Recently, a reader made a constructive comment to it suggesting 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. We looked into it and made it happen. Here is the core code along with some testing one.
public static ElementId CreateTorus2(RvtDocument famDoc, DetailArc profileArc, DetailArc pathArc)
{
ElementId ret;
CurveArrArray curveArrArr = new CurveArrArray();
CurveArray curveArr1 = new CurveArray();
curveArrArr.Append(curveArr1);
curveArr1.Append(profileArc.GeometryCurve);
SweepProfile sweepProfile = famDoc.Application.Create.NewCurveLoopsProfile(curveArrArr);
CurveArray path = new CurveArray();
path.Append(pathArc.GeometryCurve);
Plane plane = new Plane(XYZ.BasisZ, XYZ.Zero);
Sweep solid = famDoc.FamilyCreate.NewSweep(
true,
path,
famDoc.FamilyCreate.NewSketchPlane(plane),
sweepProfile,
0,
ProfilePlaneLocation.Start);
ret = solid.Id;
return ret;
}
public static IEnumerable<DetailArc> FindDetailArcs(RvtDocument doc)
{
return new FilteredElementCollector(doc)
.WherePasses(new ElementClassFilter(typeof(CurveElement), false))
.Where( f => f.GetType().Name == "DetailArc")
.Cast<DetailArc>();
}
public static void TestCreateTorus2(UIApplication uiapp)
{
RvtDocument famDoc = GetOpenOrCreateFamilyTestDoc(uiapp);
using (Transaction tr = new Transaction(famDoc, "CreateTorus2"))
{
tr.Start();
RvtDocument profileDoc = uiapp.Application.OpenDocumentFile(@"C:\Temp\Profiles.rfa");
IEnumerable<DetailArc> detailArcs = FindDetailArcs(profileDoc);
DetailArc profileArc = detailArcs.FirstOrDefault();
DetailArc pathArc = detailArcs.LastOrDefault();
CreateTorus2(famDoc, profileArc, pathArc);
profileDoc.Close();
tr.Commit();
}
}
In case some circles (DetailArc instances) have been created into a document named Profiles.rfa and residing in the C:\Temp folder,
The torus will be created nicely into the current opened or created Revit family document.
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.
Recent Comments