[摘要] Revit的场地地形其实没有什幺特别的,其实它就是一个面而已,创建这个面用下面这个方法:Form NewFormByCap(bool isSolid, Reference
Revit的场地地形其实没有什幺特别的,其实它就是一个面而已,创建这个面用下面这个方法:
Form NewFormByCap(bool isSolid, ReferenceArray profile);
如果是做成五花肉那种的,就用另一个方法:
Form NewLoftForm(bool isSolid, ReferenceArrayArray profiles);
首先用以下代码来创建一个地形面:
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 地形{ [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; //取得应用程序 using (Transaction transaction = new Transaction(revitDoc)) { transaction.Start("主题"); //在下面添加主要代码内容 //因为CurveByPoints不能是封闭曲线,所以这里建两条线 ReferencePointArray refPointArray = new ReferencePointArray(); ReferencePointArray refPointArray2= new ReferencePointArray(); ReferencePoint referencePoint1 = revitDoc.FamilyCreate.NewReferencePoint(new XYZ(0,0,0)); ReferencePoint referencePoint2 = revitDoc.FamilyCreate.NewReferencePoint(new XYZ(100, 0, 0)); ReferencePoint referencePoint3 = revitDoc.FamilyCreate.NewReferencePoint(new XYZ(100, 100, 0)); ReferencePoint referencePoint4 = revitDoc.FamilyCreate.NewReferencePoint(new XYZ(0, 100, 0)); refPointArray.Append(referencePoint1); refPointArray.Append(referencePoint2); refPointArray.Append(referencePoint3); refPointArray.Append(referencePoint4); CurveByPoints curve1 = revitDoc.FamilyCreate.NewCurveByPoints(refPointArray); refPointArray2.Append(referencePoint1); refPointArray2.Append(referencePoint4); CurveByPoints curve2 = revitDoc.FamilyCreate.NewCurveByPoints(refPointArray2); ReferenceArray profile = new ReferenceArray(); profile.Append(curve1.GeometryCurve.Reference); profile.Append(curve2.GeometryCurve.Reference); Form form = revitDoc.FamilyCreate.NewFormByCap(true, profile); transaction.Commit(); } return Result.Succeeded; } }}
结果如图:
创建有等高线的地形表面(核心还是用下面的这个api):
Form NewFormByCap(bool isSolid, ReferenceArray profile);
效果如图:
如果需要变成实体则用Form NewLoftForm(bool isSolid, ReferenceArrayArray
profiles);