0

I am using Application.Invoke() to invoke AutoLisp commands in AutoCad synchronously. Most of my commands work fine, but there are several that come up with the error

Error: AutoCAD command rejected: "_.UNDO"

The commands in particular are AutoCad Electrical commands such as c:ace_insertwire and c:wd_insym2.

Here's my code:

Using rb As New ResultBuffer()
        rb.Add(New TypedValue(LispDataType.Text, "c:wd_insym2"))
        rb.Add(New TypedValue(LispDataType.Text, name))
        rb.Add(New TypedValue(LispDataType.ListBegin))
        rb.Add(New TypedValue(LispDataType.Double, coords(0)))
        rb.Add(New TypedValue(LispDataType.Double, coords(1)))
        rb.Add(New TypedValue(LispDataType.ListEnd))
        rb.Add(New TypedValue(LispDataType.Nil))
        rb.Add(New TypedValue(LispDataType.Nil))
        Autodesk.AutoCAD.ApplicationServices.Application.Invoke(rb)
End Using

This is the equivalent of

(c:wd_insym2 "C:/ace_blocks/HT00_001.dwg" '(150 230) nil nil)

which works fine.

When I use the same method for ace_insert_wire it gives me an additional error:

Error: AutoCAD command rejected: "_.UNDO" AutoCAD command rejected: "_.REDRAW"

Any ideas what could be causing this? I certainly did not call either UNDO or REDRAW!

Bill Peet
  • 477
  • 1
  • 8
  • 23
  • can you check if the "name" parameter has spaces that AutoCAD can interpret as U or RE? – Augusto Goncalves Sep 11 '15 at 00:22
  • @AugustoGoncalves Here's an example: Invoking: ("c:wd_insym2" "//NAS/Design/ACE_Blocks/HCB11_TOL.dwg" (125 250) nil nil) Error: AutoCAD command rejected: "_.UNDO" – Bill Peet Sep 11 '15 at 00:26
  • And can you add the line of code where you call SendStringToExecute? – Augusto Goncalves Sep 11 '15 at 00:30
  • @AugustoGoncalves Sorry if my question was unclear. I am now using Application.Invoke() as shown. I will remove the first line of my question as it is confusing and unnecessary. – Bill Peet Sep 11 '15 at 00:33
  • Easy. Coordinates (x,y) are a list object. A wire cannot have a single point. There are two ends two a wire. You only have one point. – jdweng Sep 23 '15 at 23:38
  • @jdweng sorry not quite sure what you mean here. c:wdinsym2 is a command for inserting schematic components, not wires. it takes a single list xy coordinate. – Bill Peet Sep 23 '15 at 23:52
  • You posting says "ace_insert_wire". A wire is a schematic component with two ends. Each end must be an x,y coordinate. You have only one end point which is causing the error. – jdweng Sep 24 '15 at 08:08
  • @jdweng am I missing something here? My code clearly refers to c:insym2, which inserts a schematic component. Ace_insert_wire was just another example of a command that doesn’t appear to work when executing synchronously – Bill Peet Sep 24 '15 at 11:48
  • First open the text file c:insym2. It looks like it just a definition file and not a type of command. Most object in AutoCAD are added using one location point (like adding a resistor or any other object). The point can be the center or corner of the device. A wire needs have two end points. – jdweng Sep 24 '15 at 12:01

1 Answers1

2

I think it's because c:wd_insym2 is calling these commands. It fails because your own command is already active. You need to call this command asynchronously with SendStringToExecute or may be Editor.Command/CommandAsync. If you need to additional processing after the command has executed, add an handler to the CommandEnded event:

doc.CommandEnded += doc_CommandEnded;
doc.SendStringToExecute("(c:wd_insym2 "C:/ace_blocks/HT00_001.dwg" '(150 230) nil nil)", false, false, false);

[..]

void doc_CommandEnded(object sender, CommandEventArgs args)
{
    // Do what you need to do

    // Remove the handler
    doc.CommandEnded -= doc_CommandEnded;
}

You should also add an handler to the CommandFailed event in case of failure of the c:wd_insym2 command.

Maxence
  • 12,868
  • 5
  • 57
  • 69
  • Oh dear, I was hoping that wasnt the case. It seems strange that there is no satisfactory way to execute commands synchronously, surely that would be a common request? – Bill Peet Sep 14 '15 at 21:51
  • Reentrancy is a complex topic. Here you have your command, calling an Electrical command, which in turn calls another command. UNDO is a special one which can not be transacted. – Maxence Sep 15 '15 at 05:58