边界"/>
AutoCAD C# 读取Hatch边界
/// 填充边界提取转化方法/// </summary>/// <param name="hat">需要转化的Hatch对象</param>/// <param name="trans">声明的事务对象</param>/// <param name="btr">数据库中的模型空间</param>public static void DrawBorder(Hatch hatch, Transaction trans, BlockTableRecord btr){//取得边界数Point2dCollection col_point2d = new Point2dCollection();Curve2dCollection col_cur2d = new Curve2dCollection();// i=0 时 是外轮廓线,其他为内轮廓线for (int i = 0; i < hatch.NumberOfLoops; i++){col_point2d.Clear();HatchLoop hatLoop = null;try{hatLoop = hatch.GetLoopAt(i);}catch (System.Exception ex){continue;}col_cur2d = hatLoop.Curves;foreach (Curve2d curve2d in col_cur2d){// 曲线分成多少段int numSample = 2;if (curve2d.GetType().Name != "LineSegment2d") {// 如果不是直线,则计算需要制造多少段// 获取曲线的间隔(上、下界)Interval interval = curve2d.GetInterval(); double curveLength = curve2d.GetLength(interval.LowerBound, interval.UpperBound);numSample = (int)(curveLength / 0.1);if (numSample < 36){numSample = 36;}if (numSample > 360){numSample = 360;}}Point2d[] M_point2d = curve2d.GetSamplePoints(numSample);foreach (Point2d point in M_point2d){if (!col_point2d.Contains(point))col_point2d.Add(point);}}// 根据获得的Point2d点集创建闭合PolylinePolyline polyline = new Polyline();polyline.Closed = true;polyline.Color = hatch.Color;CreatePolyline(polyline, col_point2d);btr.AppendEntity(polyline);trans.AddNewlyCreatedDBObject(polyline, true);}}public static void CreatePolyline(Polyline polylineResult , Point2dCollection col_point2d){for (int i = 0; i < col_point2d.Count; i++){Point2d point = col_point2d[i];polylineResult.AddVertexAt(polylineResult.NumberOfVertices, point, 0, 0, 0);}}
参考来源:
C#CAD二次开发图案填充对象边界提取_北辰之北灬的博客-CSDN博客
AutoCAD_C#Net获取图案填充的边界线.docx_c#dxfsolid边界-C#代码类资源-CSDN下载
更多推荐
AutoCAD C# 读取Hatch边界
发布评论