AutoCad NET使用EntLast和异步命令

时间:2015-09-23 23:04:38

标签: c# .net vb.net autocad

正如我在上一个问题中发现的那样:

AutoCad Command Rejected "Undo" when using Application.Invoke()

似乎发送命令如c:wd_insym2(ACad Electrical command)无法同步调用,因为它调用了其他命令,例如Undo,导致它失败。

但是,我需要使用Lisp(entlast)或Autodesk.AutoCad.Internal.Utils.EntLast()存储我刚用命令创建的实体的EntityID。显然,如果我异步发送命令,这将无法给出正确的结果。

Maxence建议使用doc.CommandEnded处理程序,但我无法想象这将如何适合我的程序流,因为我需要单独执行每个命令,然后将新的EntityID存储在.NET变量中。

我有没有办法同时发送这些命令而不会遇到重入问题,或者异步发送命令并在继续之前等待它们执行?

1 个答案:

答案 0 :(得分:1)

您是否尝试过Java docker-java https://github.com/docker-java/docker-java Active Java docker-client https://github.com/spotify/docker-client Active (AutoCAD 2015和+):

Editor.CommandAsync

如果要在旧版本的AutoCAD中执行此操作,则会更复杂:

[CommandMethod("CMD1")]
public async void Command1()
{
  Document doc = Application.DocumentManager.MdiActiveDocument;
  Editor ed = doc.Editor;

  await ed.CommandAsync("_CMD2");

  ed.WriteMessage("Last entity handle: {0}", Utils.EntLast().Handle);
}

[CommandMethod("CMD2")]
public void Command2()
{
  Document doc = Application.DocumentManager.MdiActiveDocument;
  Database db = doc.Database;
  using (Transaction tr = db.TransactionManager.StartTransaction())
  {
    var line = new Line(new Point3d(), new Point3d(10, 20, 30));
    var currentSpace = (BlockTableRecord) tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
    currentSpace.AppendEntity(line);
    tr.AddNewlyCreatedDBObject(line, true);
    tr.Commit();
  }
}