Revit获取Element(模型)的几何信息

一.示例代码

       用途:获取元素的所有线               

public static IEnumerable<Curve> GetCurves(this Element element, ViewDetailLevel detailLevel = ViewDetailLevel.Fine, View view = null)
        {
            Options options = new Options();
            options.ComputeReferences = true;
            if (view != null)
            {
                options.View = view;
            }
            else
            {
                options.DetailLevel = detailLevel;
            }
            options.IncludeNonVisibleObjects = false;
            GeometryElement geomElem = element.get_Geometry(options);
            if (geomElem == null)
            {
                yield break;
            }
            foreach (GeometryObject geomObj in geomElem)
            {
                if (geomObj == null) continue;
                if (geomObj is Curve)
                {
                    Curve curve = geomObj as Curve;
                    if (curve != null && curve.Length > 0)
                    {
                        ElementId id = curve.Reference?.ElementId;
                        yield return curve;
                    }
                }
                else if (geomObj is GeometryInstance)
                {
                    GeometryInstance geomInst = geomObj as GeometryInstance;
                    GeometryElement instGeomElem = geomInst.GetInstanceGeometry();
                    foreach (GeometryObject instGeomObj in instGeomElem)
                    {
                        if (instGeomObj == null) continue;
                        if (instGeomObj is Curve)
                        {
                            Curve curve = instGeomObj as Curve;
                            if (curve != null && curve.Length > 0)
                            {
                                ElementId id = curve.Reference?.ElementId;
                                yield return curve;
                            }
                        }
                    }
                }
            }
            yield break;
        }
View Code

二.解析   

   Options 参数
ComputeReferences 这个是bool值 ,如果为true,返回的 Reference不为null,默认为false
DetailLevel 这个对应了视图 详细程度
IncludeNonVisibleObjects 这个是设置是否包含 不可见的几何
View  返回这个视图中可见的几何
GeometryElement:
遍历循环GeometryElement对象,可以获取
Solid---边界组成的实体,由面和边组成
Curve---线
Instance--一个Revit族实例的几何信息

上图也看到了,Instance还可以通过函数获取组实例和族样板的几何信息
GetSymbolGeometry()--获取族样本的坐标系统所表达的几何信息
GetInstanceGeometry()---获取族实例的几何信息,基于模型坐标系的几何信息。

         族样板的几何信息

                               

.其他获取几何信息的方式

                 1.如果该模型是线模型,可以通过Element.LocationCurve来获取几何信息,例:墙,梁,管道,风管,水管等

                 2.通过尺寸的引用也可以获取几何信息(Reference),这些引用包含了他们所指向的几何信息

                 3.FindReferenceByDirection方法获取几何信息

原文地址:https://www.cnblogs.com/xiaowangzi1987/p/14868043.html