private void barButtonItem49_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
PromptEntityOptions peo = new PromptEntityOptions("\n请选择实体");
PromptEntityResult per = ed.GetEntity(peo);
if (per.Status != PromptStatus.OK)
{
ObjectId objId = per.ObjectId;
Autodesk.AutoCAD.DatabaseServices.Polyline polyBnd = null;
using (DocumentLock docLock = doc.LockDocument())
{
using (Autodesk.AutoCAD.DatabaseServices.Transaction tr = db.TransactionManager.StartTransaction())
{
polyBnd = tr.GetObject(ent.ObjectId, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForWrite) as Autodesk.AutoCAD.DatabaseServices.Polyline;
}
}
Point3dCollection pLine= PolyToPoint3dCollection(polyBnd);
PromptSelectionResult entRes = ed.SelectCrossingPolygon(pLine);
if (entRes != null)
{
if (entRes.Status == PromptStatus.OK)
{
SelectionSet ssZDH = entRes.Value;
int nCount = ssZDH.Count;
Autodesk.AutoCAD.DatabaseServices.ObjectId[] oID = ssZDH.GetObjectIds();
ed.SetImpliedSelection(oID);
}
}
}
}
public Point3dCollection PolyToPoint3dCollection(Autodesk.AutoCAD.DatabaseServices.Polyline pline)
{
Point3dCollection ptColl = new Point3dCollection();
for (int i = 0; i < pline.NumberOfVertices; i++)
{
Point3d pt = pline.GetPoint3dAt(i);
if (ptColl.Count == 0)
{
ptColl.Add(pt);
}
else
{
if (IsSamePoint(ptColl[ptColl.Count - 1], pt) == false)
{
ptColl.Add(pt);
}
}
}
if (ptColl[0] == ptColl[ptColl.Count - 1])
{
ptColl.RemoveAt(ptColl.Count - 1);
}
return ptColl;
}
public const double eps = 1e-5;
public bool IsSamePoint(Point3d p1, Point3d p2)
{
return IsSamePoint(p1.X, p1.Y, p2.X, p2.Y);
}
public bool IsSamePoint(double x1, double y1, double x2, double y2)
{
if ((Math.Abs(x1 - x2) <= eps) && ((Math.Abs(y1 - y2) <= eps)))
return true;
return false;
}
AutoCAD二次开发(.Net)之多边形交叉选择
最新推荐文章于 2024-01-31 12:21:29 发布