通过使用类似命令行输入boundary的方法获取图形外轮廓,使用函数如下:
var pls = Z.ed.TraceBoundary(new Point3d(box[0] - 100, box[1]-100,0),true);
效果如下:
cs
public void XX()
{
Point3d pt = new Point3d(0, 0, 0);
List<Curve> ents = Z.db.SelectEntities<Curve>();
//Z.DrawBigBox<Curve>(ents);
List<double> box = Z.Getbox<Curve>(ents);
if (ents == null || ents.Count == 0) return;
Entity temp= Z.DrawBigBoxAdd(ents);
List<Entity> plr = new List<Entity>(); //
var pls = Z.ed.TraceBoundary(new Point3d(box[0] - 100, box[1]-100,0),true);
foreach (Entity item in pls)//不能var,否则没bounds属性
{
if (item.Bounds.Value.MinPoint.X != box[0]-1000)
{
item.Color = Color.FromRgb(255, 0, 0);
plr.Add(item);
}
}
Z.db.AddEntityToModeSpace(plr.ToArray());
Z.db.Erase(temp);
}
cs
public static List<double> Getbox<T>(List<T> entities)where T : Entity
{
List<double> lis = new List<double>();
if (entities.Count == 0)
{
return lis;
}
double minx = entities.Min(x => x.Bounds.Value.MinPoint.X);
double miny = entities.Min(x => x.Bounds.Value.MinPoint.Y);
double maxx = entities.Max(x => x.Bounds.Value.MaxPoint.X);
double maxy = entities.Max(x => x.Bounds.Value.MaxPoint.Y);
lis.Add(minx);
lis.Add(miny);
lis.Add(maxx);
lis.Add(maxy);
return lis;
}
public static Entity DrawBigBoxAdd(List<Curve> entities)
{//传进来一个list,画list的总包围盒
List<double> lis = new List<double>();
if (entities.Count == 0)
{
return null;
}
double minx = entities.Min(x => x.Bounds.Value.MinPoint.X - 1000);
double miny = entities.Min(x => x.Bounds.Value.MinPoint.Y - 1000);
double maxx = entities.Max(x => x.Bounds.Value.MaxPoint.X + 1000);
double maxy = entities.Max(x => x.Bounds.Value.MaxPoint.Y + 1000);
lis.Add(minx);
lis.Add(miny);
lis.Add(maxx);
lis.Add(maxy);
Autodesk.AutoCAD.DatabaseServices.Polyline pl = new Autodesk.AutoCAD.DatabaseServices.Polyline();
pl.AddVertexAt(0, new Point2d(minx, miny), 0, 0, 0);
pl.AddVertexAt(0, new Point2d(maxx, miny), 0, 0, 0);
pl.AddVertexAt(0, new Point2d(maxx, maxy), 0, 0, 0);
pl.AddVertexAt(0, new Point2d(minx, maxy), 0, 0, 0);
pl.Closed = true;
pl.ColorIndex = 1;
db.AddEntityToModeSpace(pl);
return pl;
}