Revit二次开发 - 算量模块 - 几何接口

Revit接口

GeometryCreationUtilities

BooleanOperationsUtils

StructuralFramingUtils

JoinGeometryUtils

二维平面开源库

https://sourceforge.net/projects/polyclipping/

平面多边形的布尔运算,非常强大,建议下载备份到本地,因为可能这样...

 


 

问题1:项目中梁柱基本都发生了剪切的关系,如果需要获取构件原始的Solid,可能就需要先打断这些关系再取,我说的可能不是很清楚,但是如果你在正在做这方面的事情时,应该会遇到这些问题并且肯定需要解决这些问题。

        /// <summary>
        /// 断开元素的剪切和连接关系
        /// </summary>
        /// <param name="element"></param>
        void Dissolve(Element element)
        {
            var document = element.Document;

            var category = ElementCategroyTypeUtils.GetCategoryType(element);

            if (category == ElementCategroyType.eBeam)
            {
                StructuralFramingUtils.DisallowJoinAtEnd(element as FamilyInstance, 0);
                StructuralFramingUtils.DisallowJoinAtEnd(element as FamilyInstance, 1);
            }

            foreach (var id in JoinGeometryUtils.GetJoinedElements(document, element))
            {
                var secondElement = document.GetElement(id);

                category = ElementCategroyTypeUtils.GetCategoryType(secondElement);

                if (category == ElementCategroyType.eBeam)
                {
                    StructuralFramingUtils.DisallowJoinAtEnd(secondElement as FamilyInstance, 0);
                    StructuralFramingUtils.DisallowJoinAtEnd(secondElement as FamilyInstance, 1);
                }

                if (JoinGeometryUtils.AreElementsJoined(document, element, secondElement))
                    JoinGeometryUtils.UnjoinGeometry(document, element, document.GetElement(id));
            }

            _document.Regenerate();
        }

使用方式需要用到事务和子事务

Solid GetOriginalSolid(Element element)
        {
            var category = ElementCategroyTypeUtils.GetCategoryType(element);
            if (
                category == ElementCategroyType.eBeam ||
                category == ElementCategroyType.eColumn)
            {
                var ins = element as FamilyInstance;

                GeometryElement geometry = null;

                using (var subTrans = new SubTransaction(_document))
                {
                    subTrans.Start();

                    Dissolve(element);

                    geometry = ins.GetOriginalGeometry(_opt);
                    var transform = ins.GetTotalTransform();
                    geometry = geometry.GetTransformed(transform);

                    foreach (var item in geometry)
                        if (item is Solid)
                        {
                            var solid = item as Solid;
                            if (solid.Faces.Size > 0)
                                return solid;
                        }
                }
            }

            throw new Exception("获取Solid失败!!!");
        }

上次代码是用来测试梁柱的,而且也没考虑多个Solid的情况,不过它能说明问题,仅供参考。

相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页