创建模型线可以使用 Document.Create.NewModelCurve(Curve,SketchPlane)方法。
第二个参数是SketchPlane工作平面。可以使用SketchPlane.Create来创建工作平面。
比如创建一条直线的模型线可以使用以下方法:
private void CreateModelLine(Document RevitDoc)
{
using (Transaction transaction = new Transaction(RevitDoc))
{
transaction.Start("Create Model Line");
Line geoLine = Line.CreateBound(XYZ.BasisY * 10, XYZ.BasisX * 10);
SketchPlane modelSketch = SketchPlane.Create(RevitDoc, RevitApp.Create.NewPlane(XYZ.BasisZ, XYZ.Zero));
ModelCurve modelLine = RevitDoc.Create.NewModelCurve(geoLine, modelSketch);
transaction.Commit();
}
}
结果:
创建了一条样条曲线可以参考以下方法:
private void CreateModelCurve2(Document RevitDoc)
{
using (Transaction transaction = new Transaction(RevitDoc))
{
transaction.Start("Create Model NurbSpline");
SketchPlane modelSketch = SketchPlane.Create(RevitDoc, RevitApp.Create.NewPlane(XYZ.BasisZ, XYZ.Zero));
NurbSpline nurbSpline = NurbSpline.Create(new List<XYZ> { new XYZ(0, 0, 0), new XYZ(15, 10, 0), new XYZ(20, 10, 0), new XYZ(25, 15, 0), new XYZ(40, 10, 0) },
new List<double> { 0.1, 0.5, 0.8, 0.3, 0.6 });
ModelCurve modelCurve = RevitDoc.Create.NewModelCurve(nurbSpline, modelSketch);
transaction.Commit();
}
}
结果:
=========【更多高级应用请关注公众号】========
==================================