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方法獲取幾何信息


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM