Revit二次开发——场地地形

如有不明白,请qq254033230询问。

Revit的场地地形其实没有什么特别的,其实它就是一个面而已,创建这个面用下面这个方法:

Form NewFormByCap(bool isSolid, ReferenceArray profile); 

如果是做成五花肉那种的,就用另一个方法:

Form NewLoftForm(bool isSolid, ReferenceArrayArray profiles); 

Revit二次开发——场地地形_第1张图片

首先用以下代码来创建一个地形面:

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;
        }
    }
}
结果如图: Revit二次开发——场地地形_第2张图片
创建有等高线的地形表面(核心还是用下面的这个api):

Form NewFormByCap(bool isSolid, ReferenceArray profile); 

效果如图:

Revit二次开发——场地地形_第3张图片

如果需要变成实体则用Form NewLoftForm(bool isSolid, ReferenceArrayArray profiles); 

你可能感兴趣的:(revit二次开发,C#)