AutoCad Command Rejected “Undo” when using Application.Invoke()

扶醉桌前 提交于 2019-12-04 06:29:53

问题


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!


回答1:


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.



来源:https://stackoverflow.com/questions/32513029/autocad-command-rejected-undo-when-using-application-invoke

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!