中望CAD HandOverTo()无法使用

名片

企业微信 用户

lv0

需求:

BUG:

已完成:

进行中:

BUG 热度

  • 需求ID:暂无
  • 需求状态: 进行中 已完成
public class ZhiPai
{
    [CommandMethod("SHL")]

    public void ShortenLines()

    {
        Document doc =

          Application.DocumentManager.MdiActiveDocument;

        Database db = doc.Database;

        Editor ed = doc.Editor;
        SelectionSet ss =

          SelectLines(ed, "\nSelect lines to shorten: ");

        if (ss != null)

        {
            Transaction tr =

              db.TransactionManager.StartOpenCloseTransaction();

            using (tr)

            {
                foreach (SelectedObject so in ss)

                {
                    Curve cur =

                      (Curve)tr.GetObject(

                        so.ObjectId,

                        OpenMode.ForWrite

                      );
                    double sp = cur.StartParam,

                          ep = cur.EndParam,

                          delta = (ep - sp) * 0.25;
                    DoubleCollection dc = new DoubleCollection();
                    dc.Add(sp + delta);
                    dc.Add(ep - delta);
                    DBObjectCollection objs = cur.GetSplitCurves(dc);
                    if (objs.Count == 3)

                    {
                        Entity ent = (Entity)objs[1];

                        cur.HandOverTo(ent, true, true);

                        tr.AddNewlyCreatedDBObject(ent, true);

                        cur.Dispose();

                        objs[0].Dispose();

                        objs[2].Dispose();

                    }

                }
                tr.Commit();

            }

        }

    }
    private SelectionSet SelectLines(Editor ed, string msg)

    {
        PromptSelectionOptions pso =

          new PromptSelectionOptions();

        pso.MessageForAdding =

          (string.IsNullOrEmpty(msg) ? "\nSelect lines: " : msg);
        TypedValue[] tvs =

          new TypedValue[1] {

        new TypedValue(

          (int)DxfCode.Start,

          "LINE"

        )

            };
        SelectionFilter sf = new SelectionFilter(tvs);
        PromptSelectionResult psr = ed.GetSelection(pso, sf);
        if (psr.Status != PromptStatus.OK || psr.Value.Count <= 0)

            return null;
        return psr.Value;

    }

}

在cur.HandOverTo(ent, true, true);显示ZwSoft.ZwCAD.Runtime.Exception: eInvalidContext异常

0 条评论 A文章作者 M管理员
    暂无讨论,说说你的看法吧
购物车
优惠劵
今日签到
有新私信 私信列表
搜索
复制链接
微信扫码
已复制到剪贴板