项目完整代码:
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.Attributes;
using System.Diagnostics;
namespace ClassLibrary3
{
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
public class Class1 : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
UIDocument uidoc = commandData.Application.ActiveUIDocument;
Document doc = uidoc.Document;
using (Transaction transaction = new Transaction(doc))
{
View view = doc.ActiveView;
//先创建一个参照平面
XYZ bubbleEnd = new XYZ(0, 0, 0);
XYZ freeEnd = new XYZ(0, 100, 0);
XYZ thirdPnt = new XYZ(0, 0, 100);
transaction.Start("Create reference plane");
ReferencePlane plane = doc.Create.NewReferencePlane2(bubbleEnd, freeEnd, thirdPnt, view);
transaction.Commit();
//创建屋顶前准备参数
Level level = doc.GetElement(new ElementId(311)) as Level;
RoofType roofType = doc.GetElement(new ElementId(335)) as RoofType;
CurveArray curveArray = new CurveArray();
curveArray.Append(Line.CreateBound(new XYZ(0, 0, 50), new XYZ(0, 50, 100)));
curveArray.Append(Line.CreateBound(new XYZ(0, 50, 100), new XYZ(0, 100, 50)));
//创建屋顶
transaction.Start("Create roof");
doc.Create.NewExtrusionRoof(curveArray, plane, level, roofType, 10, 200);
transaction.Commit();
}
return Result.Succeeded;
}
}
}
效果:
参考文献:
《Autodesk Revit 二次开发基础教程》