Polyline2d和Polyline3d和Polyfacemesh多面网格等等...
和其他的图元处理起来不太一样,
这些是复杂实体,需要通过迭代器处理.
提取点集
先看一个通用的提取点集的做法,
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++;
}
}
备注:
Polyfacemesh多面网格,里面是PolyfacemeshVertex
(完)