• Revit二次开发——轴网


    轴网

    轴网

    轴网由Element类派生的Grid类来表示。它包含所有的轴网属性和方法。继承的Name
    属性用于检索轴网线的编号圈内容。
    1.曲线(Curve )
    Grid类Curve属性获取-一个对象, 该对象代表轴线几何形状。
    ●如果IsCurved属性返回true, 则Curve属性为Arc类对象
    ●如果IsCurved属性返回false, 则Curve属性为Line类对象。

    轴网对应的类是Grid,也继承自Element
    1)轴网曲线(Curve)
    通过Grid.Curve属性能够拿到轴网的曲线,如果Grid.IsCurved返回true,那么Curve将是一个弧形曲线Arc 对象,否则就是Line对象。

    2)创建轴网
    创建轴网的函数有两个重载,分别对应于直线和弧线轴网:
    ●Document. Create. NewGrid( Arcarc)
    ●Document. Create. NewGrid(Lineline)

    2.创建轴网( Creating a Grid)
    Revit平台API中,有两个重载Document方法可用于创建新的轴网。采用不同的参
    数使用代码3-39方法,可以创建曲线或直线轴网。
    代码3- -39: NewGrid( )
    public Grid NewGrid (Arc arc);
    public Grid NewGrid (Line line );
    注意:用于创建轴网的弧线或直线必须在水平面内。

    注意:在Revit中,轴网创建时会以数字或字母顺序自动命名。
    多个轴网可以使用Document.NewGrids( )方法同时进行创建,该方法采用CurveArray
    参数。

    using System;
    using Autodesk.Revit.DB;
    using Autodesk.Revit.UI;
    
    namespace ElementBasicDemo
    {
        [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
        public class CreateGridCmd : IExternalCommand
        {
            public Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
            {
                try
                {
                    Document doc = commandData.Application.ActiveUIDocument.Document;
                    // 弧线
                    double arcRadius = 20000/304.8 ; // 弧线的内径长:英寸, 1 英寸 = 304.8mm
                    double startAngle = 0;
                    double endAngle = Math.PI / 4.0;
                    Arc arc = Arc.Create(XYZ.Zero,arcRadius,startAngle,endAngle,XYZ.BasisX,XYZ.BasisY);
    
                    // 直线
                    XYZ startPoint = XYZ.BasisY * arcRadius;
                    XYZ endPoint = XYZ.BasisX * arcRadius + startPoint;
                    Line line = Line.CreateBound(startPoint, endPoint);
    
                    using (Transaction transaction = new Transaction(doc))
                    {
                        if (transaction.Start("轴网") == TransactionStatus.Started)
                        {
                            try
                            {
                                Grid arcGrid = CreateArcGrid(doc, arc, "弧形轴网");
                                Grid lineGrid = CreateLineGrid(doc, line, "线性轴网");
                                GridType gdtype = (GridType) doc.GetElement(lineGrid.GetTypeId());
                                SetGridType(gdtype);
                               
                                if (TransactionStatus.Committed != transaction.Commit())
                                {
                                    TaskDialog.Show("失败", "轴网创建失败");
                                }
                            }
                            catch (Exception exception)
                            {
                                transaction.RollBack();
                                throw exception;
                            }
                        }
                    }
                    return Autodesk.Revit.UI.Result.Succeeded;
                }
                catch (Exception ex)
                {
                    message = ex.Message;
                    return Autodesk.Revit.UI.Result.Failed;
                }
            }
    
            private Grid CreateArcGrid(Document doc, Arc arc, string gridname)
            {
                Grid arcGrid = Grid.Create(doc, arc);
                arcGrid.Name = gridname;
                return arcGrid;
            }
    
            private Grid CreateLineGrid(Document doc, Line line, string gridname)
            {
                Grid lineGrid = Grid.Create(doc, line);
                lineGrid.Name = gridname;
                return lineGrid;
            }
    
            private GridType SetGridType(GridType gridType)
            {
                if (null != gridType)
                {
                    gridType.get_Parameter(BuiltInParameter.GRID_CENTER_SEGMENT_STYLE).SetValueString("连续");
                }
                return gridType;
            }
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    using (Transaction transaction = new Transaction(RevitDoc))
    {
       transaction.Start("Create Grid");
       Grid grid = RevitDoc.Create.NewGrid(
          Line.CreateBound(new XYZ(0, 0, 0), new XYZ(10, 10, 0)));
       grid.Name = "BB";
       transaction.Commit();
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
  • 相关阅读:
    垃圾分类资讯易语言代码
    LeetCode_位运算_中等_137.只出现一次的数字 II
    leetcode做题笔记125. 验证回文串
    Python开发者的宝典:CSV和JSON数据处理技巧大公开!
    RF和SVM的特点
    三大运营商乘风破浪,为什么离不开BAT等互联网企业?
    【目标检测】YOLO+DOTA:小样本检测策略
    深度学习:维度灾难(Curse Of Dimensionality)
    4种API性能恶化根因分析
    壁纸小程序Vue3(分类页面和用户页面基础布局)
  • 原文地址:https://blog.csdn.net/weixin_44037272/article/details/126411249