Revit二次开发之创建带洞口的楼板
今天在一个外国人的博客上看到了一个创建带洞口的楼板的方法,跟着源代码实现了一下才发现就是平常的先创建楼板,再创建洞口。但是为了记录一下自己的学习过程,还是打算写这篇博客记录自己的代码
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.Attributes;
namespace Test
{
[Autodesk.Revit.Attributes.Transaction(TransactionMode.Manual)]
[Autodesk.Revit.Attributes.Regeneration(RegenerationOption.Manual)]
public class Test:IExternalCommand
{
public Result Execute(ExternalCommandData commandData,ref string message,ElementSet elementSet)
{
UIDocument uidoc = commandData.Application.ActiveUIDocument;
Document doc = uidoc.Document;
Selection selection = uidoc.Selection;
Plane plane = Plane.CreateByNormalAndOrigin( new XYZ(0, 0, 1),XYZ.Zero);
Arc arc1 = Arc.Create(plane, 10, 0, Math.PI);
Arc arc2 = Arc.Create(plane, 10, Math.PI, Math.PI * 2);
Arc arc3 = Arc.Create(plane, 5, 0, Math.PI);
Arc arc4 = Arc.Create(plane, 5, Math.PI, Math.PI * 2);
CurveArray profile = new CurveArray();
profile.Append(arc1);
profile.Append(arc2);
CurveArray profile1 = new CurveArray();
profile1.Append(arc3);
profile1.Append(arc4);
Floor floor;
using (Transaction ts = new Transaction(doc))
{
ts.Start("floor");
floor = doc.Create.NewFloor(profile, false);
ts.Commit();
}
using (Transaction ts = new Transaction(doc))
{
ts.Start("openning");
//doc.Create.NewOpening(floor, profile1, false);
doc.Create.NewOpening(floor, profile1, false);
ts.Commit();
}
return Result.Succeeded;
}
}
}
效果如下: