获取洞口边界及在墙上开洞(Revit二次开发)

一、洞口类图

Opening
element
BoundaryCurves,BoundaryRect,Host,IsRectBoundary,IsTransparentIn3D,IsTransparentInElevation

二、获取洞口边界

如果是长方形边界,使用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   
        }  
    }  
}  

三、其他属性

  1. Host属性可以获得洞口的宿主元素。
  2. IsTransparentIn3D属性返回是否在三维视图透明,只能在族文档里使用。
  3. 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;
        }

创建结果:
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值