BIM World
A Professional BIM Learning Platform


Creating NURBSpline Curve-Shaped Steel Bars in Revit: A Guide to Secondary Development

In Revit’s API, a Nurbspline curve is represented as a series of straight line segments.

Since Revit only supports converting steel bars that are either straight or curved, a Nurbspline curve cannot be directly converted into steel bars. To work around this, you can first convert the Nurbspline model line into a sequence of continuous straight lines, and then convert those lines into steel bars.

Below is the sample code demonstrating how to convert a Nurbspline model line into continuous straight lines:

using System;
using System.Collections.Generic;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI.Selection;

// Namespace for converting Nurbspline curves to continuous straight lines
{
    [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
    [Autodesk.Revit.Attributes.Journaling(Autodesk.Revit.Attributes.JournalingMode.NoCommandData)]
    [Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)]
    public class Class1 : IExternalCommand
    {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            Document revitDoc = commandData.Application.ActiveUIDocument.Document;  // Get the active document
            Application revitApp = commandData.Application.Application;            // Get the Revit application
            UIDocument uiDoc = commandData.Application.ActiveUIDocument;            // Get the active UI document

            Selection sel = uiDoc.Selection;
            Reference ref1 = sel.PickObject(ObjectType.Element, “Select Nurb Model Line”);
            Element elem = revitDoc.GetElement(ref1);
            ModelNurbSpline nurbSpline = elem as ModelNurbSpline;

            IList<XYZ> listPoint = nurbSpline.GeometryCurve.Tessellate();

            XYZ normal = new XYZ(0, 0, 1);

            using (Transaction transaction = new Transaction(revitDoc))
            {
                transaction.Start(“Convert Nurbspline to Lines”);
                SketchPlane modelSketch = SketchPlane.Create(revitDoc, revitApp.Create.NewPlane(normal, XYZ.Zero));
                for (int i = 0; i < listPoint.Count – 1; i++)
                {
                    ModelCurve modelCurve = revitDoc.Create.NewModelCurve(Line.CreateBound(listPoint[i], listPoint[i + 1]), modelSketch);
                }
                revitDoc.Delete(nurbSpline.Id);
                transaction.Commit();
            }
            return Result.Succeeded;
        }
    }
}

xuebim
Follow the latest BIM developments in the architecture industry, explore innovative building technologies, and discover cutting-edge industry insights.
← Scan with WeChat
Like(0) 打赏
BIM WORLD » Creating NURBSpline Curve-Shaped Steel Bars in Revit: A Guide to Secondary Development

Comment Get first!

Must log in before commenting!

 

BIM World, A Professional BIM Learning Platform

Stay updated on the latest architecture trends and share new building technologies.

Contact UsAbout Us

觉得文章有用就打赏一下小编吧

非常感谢你的打赏,我们将继续提供更多优质内容,让我们一起创建更加美好的网络世界!

支付宝扫一扫

微信扫一扫

Account Login

By signing in, you agree toUser Agreement

Sign Up