civil 3d 體積曲面提取等高線


為了求兩個曲面的交線,

采用創建體積曲面並提取高程為0的等高線方法來迂回實現,

因缺少.net api,

不得不使用com api,

對於不熟悉Com用法的朋友(比如我自己),

可能會卡在這樣那樣的問題上,

這些問題在網絡上能搜索到的有效信息比較少,

因而解決起來也比較麻煩。

 

難點在於類型的轉換,

吃不准對象的類型,

轉換就會失敗。

 

private void CreateSurfaceIntersectionLines(ref List<Point2dCollection> ptss)
{
    //獲取曲面樣式Id
    ObjectId volumeSurfaceStyleId = GetVolumeSurfaceStyleId();
    //創建體積曲面
    var volumeSurfaceId = TinVolumeSurface.Create("輔助體積曲面", egSurfaceId, gradingSurfaceId, volumeSurfaceStyleId);
    //獲取Com對象
    AeccTinVolumeSurface aeccTVS = _comDoc.ObjectIdToObject((volumeSurfaceId.OldIdPtr).ToInt64()) as AeccTinVolumeSurface;
    //提取等高線
    IEnumerable contours = aeccTVS.ExtractContour(AeccDisplayOrientation.aeccDisplayOrientationPlan, AeccSurfaceFilterType.aeccSFMajorContours, 0, 0) as IEnumerable;
    //頂點集合,可能存在多條等高線,所以需要用集合
    //List<Point2dCollection> ptss = new List<Point2dCollection>();
    foreach (var contour in contours)
    {
        //轉換為AcadLWPolyline,起初轉為AcadPolyline,類型不對
        AcadLWPolyline pl = contour as AcadLWPolyline;
        if (pl != null)
        {
            Point2dCollection pts = new Point2dCollection();
            //坐標是以doulbe數組形式存儲的
            double[] cors = pl.Coordinates as double[];
            for (int i = 0; i < cors.Length - 2; i += 2)
            {
                pts.Add(new Point2d(cors[i], cors[i + 1]));
            }
            ptss.Add(pts);
            //刪除多段線
            pl.Delete();
        }
    }
    //刪除輔助體積曲面
    aeccTVS.Delete();
}

 


免責聲明!

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



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