Polyline2d和Polyline3d的点更改,它和其他的图元处理起来不一样.
因为这些是复杂实体,需要通过枚举值来处理.
提取点集
先看一个通用的提取点集的做法,
GetStretchPoints可以作用在:轻多段线/二维多段线/三维多段线
你只需要将Polyline2d改成其他即可.
之所以改成List<Point3d>是因为用上Linq,微软大法好啊!
/// <summary>
/// 二维多段线点集
/// </summary>
public static List<Point3d> GetPoint3ds(this Polyline2d pl)
{
var pts3d = new Point3dCollection();
pl.GetStretchPoints(pts3d);
var lst = new List<Point3d>();
foreach (Point3d item in pts3d)
{
lst.Add(item);
}
return lst;
}
将二维多段线的点集逆序
IsClockwise 判断是否顺时针,可参考叉乘判断
//打开图元
var ent = tr.GetObject(item, OpenMode.ForWrite) as Entity;
if (ent is Polyline2d pl2d)
{
var pts3d = pl2d.GetPoint3ds();
if (!IsClockwise(pts3d))//判断是否顺时针
{
continue;
}
int j = 0;
var pl2dEnu = pl2d.GetEnumerator();
while (pl2dEnu.MoveNext())
{
if (j > 0)
{
var id = (ObjectId)pl2dEnu.Current;
var vtx = tr.GetObject(id, OpenMode.ForWrite) as Vertex2d;
vtx.Position = pts3d[pts3d.Count - j];
}
j++;
}
}
(完)