Creating a curved beam using the Revit API is quite straightforward – as long as the specific overload of the NewFamilyInstance() method that can create the curved beam is known. For example, it has been commonly seen that using the following overload of the NewFamilyInstance() method:
NewFamilyInstance(XYZ, FamilySymbol, StructuralType)
does create a beam but attempting to set the LocationCurve.Curve of this beam to be a curve (arc) does not work. The beam created using the specific overload shown above only expects the LocationCurve to be a Line (and not an Arc).
The following code snippet shows one of the simplest ways of creating a curved beam.
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using Autodesk.Revit.ApplicationServices;
namespace Revit.SDK.Samples.HelloRevit.CS
{
[Transaction(TransactionMode.Manual)]
public class Command : IExternalCommand
{
public Result Execute(ExternalCommandData commandData,
ref string message,
ElementSet elements)
{
UIApplication app = commandData.Application;
Document doc = app.ActiveUIDocument.Document;
XYZ end0 = new XYZ(0, 0, 0);
XYZ end1 = new XYZ(10, 10, 10);
XYZ pointOnCurve = new XYZ(10, 0, 0);
Arc arc = app.Application.Create.NewArc(
end0, end1, pointOnCurve);
FilteredElementCollector coll =
new FilteredElementCollector(doc).OfClass(typeof(Level));
Level lvl = coll.ToElements()[0] as Level;
FilteredElementCollector symbolCollector =
new FilteredElementCollector(doc).OfClass(typeof(FamilySymbol));
var targetElems =
from FamilySymbol newFamilySymbol
in symbolCollector
where newFamilySymbol.Name.Equals("C15X50")
select newFamilySymbol;
using (Transaction trans = new Transaction(doc, "beam"))
{
trans.Start();
FamilyInstance curvedBeam =
doc.FamilyCreate.NewFamilyInstance(
new XYZ(0,0,0),
targetElems.ElementAt(0),
lvl,
Autodesk.Revit.DB.Structure.StructuralType.Beam);
LocationCurve locationCurve = curvedBeam.Location as LocationCurve;
locationCurve.Curve = arc;
trans.Commit();
}
return Result.Succeeded;
}
}
}
The output generated using this simple code is included below – a curved beam, as desired: