一、洞口类图
二、获取洞口边界
如果是长方形边界,使用BoundaryRect属性,其他形状边界使用BoundaryCurves属性。
方法示例:
private void GetBoundary(Opening opening)
{
if (opening.IsRectBoundary)
{
XYZ startPoint = opening.BoundaryRect[0];
XYZ endPoint = opening.BoundaryRect[1];
}
else {
foreach (Curve curve in opening.BoundaryCurves)
{
//遍历Curve
}
}
}
三、其他属性
- Host属性可以获得洞口的宿主元素。
- IsTransparentIn3D属性返回是否在三维视图透明,只能在族文档里使用。
- IsTransparentlnElevation属性返回是否在里面视图透明,只能在族文档里使用。
四、创建洞口
API方法: NewOpening( Wall wall,XYZ pntStart, XYZ pntEnd),可以在墙上创建洞口,参数意义如下:
• wall:墙对象。
• pntStart:长方形的一个顶点。
• pntEnd:长方形的另一个对角的顶点。
在墙上开洞方法示例:
private void CreateOpening(Document RevitDoc, Wall wall)
{
LocationCurve locationCurve = wall.Location as LocationCurve;
Line location = locationCurve.Curve as Line;
XYZ startPoint = location.GetEndPoint(0);
XYZ endPoint = location.GetEndPoint(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();
Opening opening = RevitDoc.Create.NewOpening(wall, startPoint + delta, startPoint + delta * 2);
transaction.Commit();
}
}
主程序调用:
Reference pickedRef = null;
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
Document doc = commandData.Application.ActiveUIDocument.Document;
UIApplication uiApp = commandData.Application;
Selection sel = uiApp.ActiveUIDocument.Selection;
pickedRef = sel.PickObject(ObjectType.Element, "选择一个族实例");
Element elem1 = doc.GetElement(pickedRef);
Wall wall1 = elem1 as Wall;
try
{
CreateOpening(doc, wall1);
}
catch
{
}
return Result.Succeeded;
}
创建结果: