【Revit】 Revit二次开发针对墙创建剖切面

任何一个视图View,有三个方向,分别是ViewDirection(朝着观察者的方向),RightDirection(朝着屏幕的右边),UpDirection(朝着屏幕的上边)。

ViewSection.CreatSection方法,可以创建剖面,该方法中的第三个参数是一个BoundingBoxXYZ类型:sectionBox。

sectionBox.Transform.BasisZ的值指定了生成的剖面的ViewDirection;

sectionBox.Transform.BasisY的值指定了生成的剖面的UpDirection;

sectionBox.Transform.BasisX的值指定了生成的剖面的RightDirection;

直接上代码:

复制代码
        /// <summary>
        /// 创建墙剖面图
        /// </summary>
        /// <param name="wall"></param>
        /// <param name="viewFamilyType"></param>
        /// <param name="centerloc">中间点的位置(单位英寸)</param>
        /// <param name="direction">方向(单位英寸)</param>
        /// <param name="depth">深度(单位英寸)</param>
        /// <returns></returns>
        private Element CreateWallSection(Wall wall, ViewFamilyType viewFamilyType, XYZ centerloc, XYZ direction, double depth = 5)
        {
            try
            {
                if (wall == null) return null;
                var line = ((wall.Location as LocationCurve).Curve as Autodesk.Revit.DB.Line);
                var length = line.Length / 2 + 0.5;
                var box = wall.get_BoundingBox(null);
                var min = new XYZ(-length, box.Min.Z, 0);
                var max = new XYZ(length, box.Max.Z, depth);
                var center = new XYZ(centerloc.X, centerloc.Y, (box.Min.Z + box.Max.Z) / 2);

                Transform transform = Transform.Identity;
                transform.Origin = center;
                transform.BasisX = -direction.CrossProduct(XYZ.BasisZ).Normalize();
                transform.BasisY = XYZ.BasisZ;
                transform.BasisZ = direction;
                var newbox = new BoundingBoxXYZ() { Min = min, Max = max, Transform = transform };

                ViewSection viewSection = null;
          //开事务
                TransactionUtils.InvokeTransaction(_doc, "创建墙剖面", () =>
                {
                    viewSection = ViewSection.CreateSection(_doc, viewFamilyType.Id, newbox);
                    viewSection.SetViewName("剖面_" + wall.Id.IntegerValue);
                    viewSection.CropBoxActive = true;
                    viewSection.DisplayStyle = DisplayStyle.ShadingWithEdges;
                    viewSection.DetailLevel = ViewDetailLevel.Fine;
                    viewSection.IsolateElementTemporary(wall.Id);
                });
                return viewSection;
            }
            catch
            { return null; }
        }
复制代码

其中:

//筛选对应的类型,此处使用了自己写的扩展方法
ViewFamilyType viewFamilyType = _doc.WherePasses(new ElementClassFilter(typeof(ViewFamilyType))).FirstOrDefault(x => ViewFamily.Section == (x as ViewFamilyType).ViewFamily) as ViewFamilyType;

 

posted on   梦琪小生  阅读(147)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
历史上的今天:
2017-08-12 【转】【Java/Android】Intent的简介以及属性的详解
< 2025年3月 >
23 24 25 26 27 28 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 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示