c# - 在AutoCAD中使用Editor类执行命令

标签 c# command autocad autocad-plugin

我正在尝试创建一个按钮,当按下该按钮时,它会标记绘图的位置。现在该方法看起来像这样。

[CommandMethod("MARKPOS", CommandFlags.Session)]
public void MarkPosition()
{
    Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
    ed.Command("UNDO", "M");
}

但是,当我尝试执行该方法时,出现下图所示的错误并且无法确定原因。

enter image description here

************** 异常文本 ************** Autodesk.AutoCAD.Runtime.Exception:eInvalidInput 在 Autodesk.AutoCAD.EditorInput.Editor.Command(对象 [] 参数) 在 c:\Users\nickg\Documents\All Code\autocad-adapter\IOAutoCADHandler\myCommands.cs 中的 AutoCAD_Adapter.MyCommands.MarkPosition():第 186 行 在 Autodesk.AutoCAD.Runtime.CommandClass.InvokeWorker(MethodInfo mi,Object commandObject,Boolean bLispFunction) 在 Autodesk.AutoCAD.Runtime.CommandClass.InvokeWorkerWithExceptionFilter(MethodInfo mi,Object commandObject,Boolean bLispFunction) 在 Autodesk.AutoCAD.Runtime.PerDocumentCommandClass.Invoke(MethodInfo mi,Boolean bLispFunction) 在 Autodesk.AutoCAD.Runtime.CommandClass.CommandThunk.Invoke()

最佳答案

SendStringToExecute 将在 AutoCAD 2014 之前有效。在 AutoCAD 2015(及更新版本)上,它已被 Editor.Command 或 Editor.CommandAsync 取代。

关于原代码,请尝试

[CommandMethod("MARKPOS")]
public static void MarkPosition()
{
  Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
  ed.Command(new object[]{"UNDO", "M"});
}

关于c# - 在AutoCAD中使用Editor类执行命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29496996/

相关文章:

c# - 为隐式转换启用编译器警告 (C#)

C# 可以给类起别名吗(不是 'using' )

c# - 如果 c# 中的值为 null,则为对象分配默认值

python - 在 Python 中运行命令

mysql - 尝试在 AutoCAD 和 mySQL 之间创建链接以自动完成其他属性

c# - 使用 Entity Framework 4 以编程方式读取外键元数据

command-line - 如何获取所有以常用单词开头的Windows服务名称?

c# - 使用多个命令在类中预定义字段

c++ - 解析挤出方向 vector DXF

visual-studio-2010 - Visual Studio 2010 中使用 Entity Framework 4.1 面向 x64 平台