revit二次开发中nurbspline曲线的表现形式实际上是一系列的直线组成的。
由于revit只支持直线或者圆曲线的钢筋变成钢筋。所以不能将nurbspline曲线转成钢筋,所以可以先将nurbspline模型线转连续的直线,然后再转成钢筋即可。
其中,nurbspline模型线线转成连续的直线的代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI.Selection;
using Autodesk.Revit.ApplicationServices;
namespace nurb曲线转连续的直线
{
[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; //取得文档
Application revitApp = commandData.Application.Application; //取得应用程序
UIDocument uiDoc = commandData.Application.ActiveUIDocument; //取得当前活动文档
Selection sel = uiDoc.Selection;
Reference ref1 = sel.PickObject(ObjectType.Element, “选择nurb模型线”);
Element elem = revitDoc.GetElement(ref1);
ModelNurbSpline nurbSpline = elem as ModelNurbSpline;
IList<XYZ> listPoint = new List<XYZ>();
listPoint= nurbSpline.GeometryCurve.Tessellate();
XYZ normal = new XYZ(0, 0, 1);
using (Transaction transaction = new Transaction(revitDoc))
{
transaction.Start(“主题”);
//在下面添加主要代码内容
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;
}
}
}
评论前必须登录!
注册