Author Topic: Sending Lisp Commands Asynchronously in AutoCad 2013  (Read 2224 times)

0 Members and 1 Guest are viewing this topic.

BillPeet

  • Guest
Sending Lisp Commands Asynchronously in AutoCad 2013
« on: September 28, 2015, 08:15:39 PM »
I need to use the inbuilt AutoCad Electrical functions in my addon (I am using AutoCad Electrical 2013 BTW). I need the commands to be executed synchronously, as I am recording the object ids of the components created by the commands, to be used in later commands.

I have played around with several different synchronous methods, including acedCmd, AcadEvapLisp, and Application.Invoke (my favourite), sending commands as both concatenated strings and resultbuffers, etc, which works *most* of the time. However there are several commands (e.g. c:wd_insym2) that give me the error: AutoCAD command rejected: "_.UNDO". Maxence on StackOverflow told me that this could be because of some reentrancy issue, as I have my command calling and ACad Electrical command, which in turn calls the UNDO command. Is this correct?

Another thing Maxence suggested was to use an Asynchronous method and use the Await operator to wait for the command to be executed before continuing.
Code - C#: [Select]
  1. Await ed.CommandAsync("(c:wd_insym2 "C:/blocks/HT00_001.dwg" '(150 230) nil nil)");
  2. ed.WriteMessage("Last entity handle: {0}", Utils.EntLast().Handle);
However, the example uses ed.CommandAsync(), which is new in AutoCad 2015. I can't seem to find any AutoCad 2013 API methods that can be called in this way (e.g. Await doc.SendStringToExecute() comes up with an error saying "Expression does not produce a value".

Any ideas/suggestions as to how I can either send ALL commands synchronously, or alternatively send them asynchronously and use Await, using pre-2015 methods?

Thanks a lot.