在墙上开洞口的代码可以参考这个:
Wall wall = GetElement<Wall>(185520);
LocationCurve locationCurve = wall.Location as LocationCurve;
Line location = locationCurve.Curve as Line;
XYZ startPoint = location.get_EndPoint(0);
XYZ endPoint = location.get_EndPoint(1);
Parameter wallHeightParameter =
wall.get_Parameter(BuiltInParameter.WALL_USER_HEIGHT_PARAM);
double wallHeight = wallHeightParameter.AsDouble();
XYZ delta = (endPoint - startPoint + new XYZ(0, 0, wallHeight)) / 3;
using (Transaction transaction = new Transaction(RevitDoc))
{
transaction.Start("Create Opening on wall");
Opening opening = RevitDoc.Create.NewOpening(wall, startPoint + delta, startPoint + delta * 2);
transaction.Commit();
}
在屋顶创建洞口的代码参考这个:
using (Transaction transaction = new Transaction(RevitDoc))
{
//创建屋顶前准备参数
Level level = RevitDoc.GetElement(new ElementId(311)) as Level;
RoofType roofType = RevitDoc.GetElement(new ElementId(335)) as RoofType;
CurveArray curveArray = new CurveArray();
//屋顶外边框
curveArray.Append(Line.CreateBound(new XYZ(0, 0, 0), new XYZ(30, 0, 0)));
curveArray.Append(Line.CreateBound(new XYZ(30, 0, 0), new XYZ(30, 30, 0)));
curveArray.Append(Line.CreateBound(new XYZ(30, 30, 0), new XYZ(0, 30, 0)));
curveArray.Append(Line.CreateBound(new XYZ(0, 30, 0), new XYZ(0, 0, 0)));
//在中间添加洞口
curveArray.Append(Line.CreateBound(new XYZ(5, 5, 0), new XYZ(5, 15, 0)));
curveArray.Append(Line.CreateBound(new XYZ(5, 15, 0), new XYZ(15, 5, 0)));
curveArray.Append(Line.CreateBound(new XYZ(15, 5, 0), new XYZ(5, 5, 0)));
//创建屋顶
transaction.Start("Create roof");
ModelCurveArray modelCurveArray = new ModelCurveArray();
FootPrintRoof roof =
RevitDoc.Create.NewFootPrintRoof(curveArray, level, roofType, out modelCurveArray);
//设置屋顶坡度
ModelCurve curve1 = modelCurveArray.get_Item(0);
ModelCurve curve3 = modelCurveArray.get_Item(2);
roof.set_DefinesSlope(curve1, true);
roof.set_SlopeAngle(curve1, 0.5);
roof.set_DefinesSlope(curve3, true);
roof.set_SlopeAngle(curve3, 1.6);
transaction.Commit();
}
=========【更多高级应用请关注公众号】========
===================================