AutoCAD二次开发(.Net)之多边形交叉选择

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;
}

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值