首页 > 其他分享 >Revit二次开发——创建墙

Revit二次开发——创建墙

时间:2022-09-07 12:22:52浏览次数:70  
标签:int 创建 XYZ wall double 二次开发 new Line Revit

创建墙测试

 [Autodesk.Revit.Attributes.Transaction(TransactionMode.Manual)]
    [Autodesk.Revit.Attributes.Regeneration(RegenerationOption.Manual)]

    public class AxWallCreate : IExternalCommand
    {
        Autodesk.Revit.ApplicationServices.Application app;
        Autodesk.Revit.DB.Document doc;
        List<AxWallLine> m_WallPolylines = null;
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIApplication uiApp = commandData.Application;
            UIDocument uiDoc = uiApp.ActiveUIDocument;
            app = uiApp.Application;
            doc = uiDoc.Document;
            Selection selection = uiDoc.Selection;
            OpenFileDialog dlg = new OpenFileDialog();
            dlg.Title = "打开墙线文件";
            dlg.Filter = "(*.shp)|*.shp";
            if (dlg.ShowDialog() == DialogResult.OK && dlg.FileName != String.Empty)
            {
                String wallFileName = dlg.FileName;
                MessageBox.Show(wallFileName);
                ReadWallLinesSHP(wallFileName);
                String info = "读取线的数目:" + m_WallPolylines.Count;

                MessageBox.Show(info, "信息");              
                CreateWall();
            }

            return Result.Succeeded;
        }

        //读取墙线文件
        private void ReadWallLinesSHP(string FILENAME)
        {
            IntPtr hShp;
            hShp = ShapeLib.SHPOpen(FILENAME, "rb+");
            m_WallPolylines = new List<AxWallLine>();
            // get shape info and verify shapes were created correctly
            double[] minB = new double[4];
            double[] maxB = new double[4];
            int nEntities = 0;
            ShapeLib.ShapeType shapeType = 0;
            ShapeLib.SHPGetInfo(hShp, ref nEntities, ref shapeType, minB, maxB);
            double m_MinX = minB[0];
            double m_MinY = minB[1];
            for (int i = 0; i < nEntities; i++)
            {
                int iShape = i;
                IntPtr pshpObj = ShapeLib.SHPReadObject(hShp, iShape);
                AxPolyline2d plline = new AxPolyline2d();
                ShapeLib.SHPObject shpObj = new ShapeLib.SHPObject();
                Marshal.PtrToStructure(pshpObj, shpObj);

                int parts = shpObj.nParts;
                if (parts > 0)
                {
                    int[] partStart = new int[parts];
                    Marshal.Copy(shpObj.paPartStart, partStart, 0, parts);
                    int[] partType = new int[parts];
                    Marshal.Copy(shpObj.paPartType, partType, 0, parts);

                    int number = shpObj.nVertices;
                    double[] m_padfX = new double[number];
                    Marshal.Copy(shpObj.padfX, m_padfX, 0, number);
                    double[] m_padfY = new double[number];
                    Marshal.Copy(shpObj.padfY, m_padfY, 0, number);
                    for (int iv = 0; iv < number; iv++)
                    {
                        double x = m_padfX[iv];
                        double y = m_padfY[iv];
                        x = x - minB[0];
                        y = y - minB[1];
                        Vector2d pt = new Vector2d(x * 1000, y * 1000);
                        plline.polyline.Add(pt);//
                    }
                    AxWallLine wall = new AxWallLine();
                    wall.WallId = 1000 + i;
                    wall.m_Polyline = plline;
                    wall.m_MaxZ = 3000;
                    wall.m_MinZ = 0;
                    wall.m_Thickness = 150;
                    m_WallPolylines.Add(wall);
                }
                ShapeLib.SHPDestroyObject(pshpObj);
            }
            ShapeLib.SHPClose(hShp);
        }

        public void CreateWall()
        {
            //List<Curve>;
            IList<Curve> curves = new List<Curve>();
            Line l1 = Line.CreateBound(XYZ.Zero, new XYZ(150, 0, 0));
            Line l2 = Line.CreateBound(XYZ.Zero, new XYZ(50, 0, 50));
            Line l3 = Line.CreateBound(new XYZ(50, 0, 50), new XYZ(100, 0, 50));
            Line l4 = Line.CreateBound(new XYZ(100, 0, 50), new XYZ(150, 0, 0));
            curves.Add(l1);
            curves.Add(l2);
            curves.Add(l3);
            curves.Add(l4);

            using (Transaction ts = new Transaction(doc,"AxCreateWall"))
            {
                ts.Start();
                Wall.Create(doc, curves, false);
                ts.Commit();
            }

            for (int i = 0; i < m_WallPolylines.Count; i++)
            {
                AxWallLine wall = m_WallPolylines[i];
                List<Vector2d> segments = wall.m_Polyline.polyline;
                for (int j = 0; j < segments.Count-1; j++)
                {
                    Vector2d segment0 = segments[j];
                    Vector2d segment1 = segments[j+1];
                    XYZ pt0 = new XYZ(segment0.X, segment0.Y, 0);
                    XYZ pt1 = new XYZ(segment1.X, segment1.Y, 0);
                    Line line = Line.CreateBound(pt0, pt1);

                    //Wall.Create(doc, line, true);
                }            
            }
        }
    }

  

 

 

标签:int,创建,XYZ,wall,double,二次开发,new,Line,Revit
From: https://www.cnblogs.com/yhlx125/p/16664964.html

相关文章

  • 创建数组
    创建数组数组的概念数组是指一组数据的集合,其中每个数据被称作元素,在数组中可以存放任意类型的元素。数组是一种将一组数据存储在单个变量名下的优雅方式。1.利用new创......
  • 使用 Codex AI 逐步创建 Wordle
    使用CodexAI逐步创建Wordle我转录了使用自然语言创建工作单词的说明TL;DR:如何在不编程的情况下创建Wordle几个月前,我观看了一段关于使用AI创建Wordle的视频......
  • 【数据库】Oracle建表、创建序列、添加触发器生成自增主键
    CREATETABLE"TEST"."T_ORDER"(  "AUUID_0"VARCHAR2(255)NOTNULLENABLE,  "Order_ID"VARCHAR2(255)NOTNULLENABLE,  "User_ID"VARCHAR2(25......
  • 让我们学习,如何使用 python 创建自己的端口扫描器
    让我们学习,如何使用python创建自己的端口扫描器PortScannerPythonPicture本教程仅包含用于创建端口扫描器的四个不同代码片段。这些端口扫描器将为Web服务和外部......
  • 一篇文章教你如何用界面组件DevExpress WPF创建一个WPF视图模型
    DevExpressWPF拥有120+个控件和库,将帮助您交付满足甚至超出企业需求的高性能业务应用程序。通过DevExpressWPF能创建有着强大互动功能的XAML基础应用程序,这些应用程序专......
  • 在UNI-APP创建VUE3项目时配置VUE版本
    在UNI-APP创建项目时,默认是VUE2版本。如果直接使用VUE3代码时会出错。所以第一步就要求设置VUE版本,操作如下:打开根目录下/manifest.json文件,找到“基础配置”-->"Vue......
  • 使用 testing-library-selector 创建可重用的选择器
    使用testing-library-selector创建可重用的选择器像你们中的许多人一样,我喜欢重用代码,从而尽可能减少重复。我发现了什么测试库查询是我在不同的测试文件中一遍又一......
  • 项目创建
    (1)新建项目(2)选择maven方式   (3)设置gav  (4)设置打包方式war包,并引入依赖  (5)添加web模块;注意:需要出现小圆点,未出现的原因,模块放错位置,或未在pom中配置<p......
  • Java中如何创建不可变(immutable)类
    什么是不可变类1.不可变类是指类的实例一经创建完成,这个实例的内容就不会改变。2.Java中的String和八个基本类型的包装类(Integer,Short,Byte,Long,Double,Float,......
  • Linux学习笔记:mkdir创建文件夹
    Linux学习笔记:mkdir创建文件夹文件夹,即目录,在linux中使用mkdir创建。语法:mkdirdir_name通过mkdir命令可以实现在指定位置创建以dir_name(指定的文件名......