/// 填充边界提取转化方法
/// </summary>
/// <param name="hat">需要转化的Hatch对象</param>
/// <param name="trans">声明的事务对象</param>
/// <param name="btr">数据库中的模型空间</param>
/// <param name="numSample">提取单位曲线中样本点的数目</param>
public static void DrawBorder(Hatch hat, Transaction trans, BlockTableRecord btr, int numSample)
{
//取得边界数
int loopNum = hat.NumberOfLoops;
Point2dCollection col_point2d = new Point2dCollection();
BulgeVertexCollection col_ver = new BulgeVertexCollection();
Curve2dCollection col_cur2d = new Curve2dCollection();
for (int i = 0; i < loopNum; i++)
{
col_point2d.Clear();
HatchLoop hatLoop = null;
try
{
hatLoop = hat.GetLoopAt(i);
}
catch (System.Exception)
{
continue;
}
//如果HatchLoop为PolyLine
if (hatLoop.IsPolyline)
{
col_ver = hatLoop.Polyline;
foreach (BulgeVertex vertex in col_ver)
{
col_point2d.Add(vertex.Vertex);
}
}
//如果HatchLoop为Curves
else
{
col_cur2d = hatLoop.Curves;
foreach (Curve2d item in col_cur2d)
{
Point2d[] M_point2d = item.GetSamplePoints(numSample);
foreach (Point2d point in M_point2d)
{
if (!col_point2d.Contains(point))
col_point2d.Add(point);
}
}
}
//根据获得的Point2d点集创建闭合Polyline
Polyline pl = new Polyline();
pl.Closed = true;
pl.Color = hat.Color;
PolylineTools.CreatePolyline(pl, col_point2d);
btr.AppendEntity(pl);
trans.AddNewlyCreatedDBObject(pl, true);
}
}
C#CAD二次开发图案填充对象边界提取
最新推荐文章于 2024-10-08 17:40:31 发布