為了求兩個曲面的交線,
采用創建體積曲面並提取高程為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(); }