Revit API创建几何实体Solid并找到与之相交的元素

几何实体的创建方法之一:
构成封闭底面,指定拉伸方向与拉伸高度。GeometryCreationUtilities
// 自创几何实体相交法
[TransactionAttribute(Autodesk.Revit.Attributes.TransactionMode.Manual)]
public  class FindIntersectWallsByGeometry : IExternalCommand
{
     public Result Execute(ExternalCommandData commandData,  ref  string messages, ElementSet elements)
    {

        UIApplication app = commandData.Application;
        Document doc = app.ActiveUIDocument.Document;
        Transaction trans =  new Transaction(doc,  " ExComm ");
        trans.Start();

         // pick a point to draw solid在屏幕上选择一点,找到附近的墙。
        Selection sel = app.ActiveUIDocument.Selection;
        XYZ pt = sel.PickPoint( " Please pick a point to get the close walls ");

         // XYZ pttemp1 = sel.PickPoint(Autodesk.Revit.UI.Selection.ObjectSnapTypes.None, "Pick leader end...");
        
// XYZ pttemp2 = sel.PickPoint(Autodesk.Revit.UI.Selection.ObjectSnapTypes.None, "Pick leader elbow...");

        
//
         double dBoxLength =  3;
         // Z值不变,以选择的点为中心,找到矩形四个点。
        XYZ pt1 =  new XYZ(pt.X - dBoxLength /  2, pt.Y - dBoxLength /  2, pt.Z);
        XYZ pt2 =  new XYZ(pt.X + dBoxLength /  2, pt.Y - dBoxLength /  2, pt.Z);
        XYZ pt3 =  new XYZ(pt.X + dBoxLength /  2, pt.Y + dBoxLength /  2, pt.Z);
        XYZ pt4 =  new XYZ(pt.X - dBoxLength /  2, pt.Y + dBoxLength /  2, pt.Z);
         // 创建四条线。
        Line lineBottom = app.Application.Create.NewLineBound(pt1, pt2);
        Line lineRight = app.Application.Create.NewLineBound(pt2, pt3);
        Line lineTop = app.Application.Create.NewLineBound(pt3, pt4);
        Line lineLeft = app.Application.Create.NewLineBound(pt4, pt1);
         // 封闭曲线
        CurveLoop profile =  new CurveLoop();
        profile.Append(lineBottom);
        profile.Append(lineRight);
        profile.Append(lineTop);
        profile.Append(lineLeft);

        List<CurveLoop> loops =  new List<CurveLoop>();
        loops.Add(profile);
         // 创建实体的方法(底面,拉伸方向,拉伸高度)
        XYZ vector =  new XYZ( 001);
        Solid solid = GeometryCreationUtilities.CreateExtrusionGeometry(loops, vector,  10);

         // 相交过滤器
        FilteredElementCollector collector =  new FilteredElementCollector(doc);
        ElementIntersectsSolidFilter solidFilter =  new ElementIntersectsSolidFilter(solid);

        collector.WherePasses(solidFilter);

        sel.Elements.Clear();
         // Add these interseting element to the selection
         foreach (Element elem  in collector)
        {
            sel.Elements.Add(elem);
        }

        trans.Commit();
         return Result.Succeeded;
    }
}
url: http://greatverve.cnblogs.com/p/GeometryCreationUtilities.html
  • 0
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值