AutoCad 命令拒绝“撤消"使用 Application.Invoke() 时 [英] AutoCad Command Rejected "Undo" when using Application.Invoke()

查看:22
本文介绍了AutoCad 命令拒绝“撤消"使用 Application.Invoke() 时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Application.Invoke() 在 AutoCad 中同步调用 AutoLisp 命令.我的大多数命令都可以正常工作,但有几个命令会出现错误

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"

特别是命令是 AutoCad Electrical 命令,例如 c:ace_insertwire 和 c:wd_insym2.

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

这是我的代码:

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

这相当于

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

效果很好.

当我对 ace_insert_wire 使用相同的方法时,它给了我一个额外的错误:

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"

任何想法可能导致这种情况?我当然没有调用 UNDO 或 REDRAW!

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

推荐答案

我认为这是因为 c:wd_insym2 正在调用这些命令.它失败是因为您自己的命令已经处于活动状态.您需要使用 SendStringToExecuteEditor.Command/CommandAsync 异步调用此命令.如果您需要在命令执行后进行额外处理,请向 CommandEnded 事件添加一个处理程序:

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;
}

您还应该为 CommandFailed 事件添加一个处理程序,以防 c:wd_insym2 命令失败.

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

这篇关于AutoCad 命令拒绝“撤消"使用 Application.Invoke() 时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆