zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    three.js 制作一个三维的推箱子游戏
    three.js 郭先生制作太阳系
    three.js 制作魔方
    three.js 欧拉角和四元数
    mysql
    重装系统后需要安装的软件
    python3.7 安装PyQt5
    Java读取文件
    linux 环境jdk安装
    linux 修改用户字符集
  • 原文地址:https://www.cnblogs.com/greatverve/p/GeometryCreationUtilities.html
Copyright © 2011-2022 走看看