我正在尝试创建一个按钮,按下该按钮会标记绘图的位置。现在这个方法看起来像这样。
[CommandMethod("MARKPOS", CommandFlags.Session)]
public void MarkPosition()
{
Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
ed.Command("UNDO", "M");
}
然而,当我尝试执行该方法时,我得到下图所示的错误,无法确定原因。
**************例外文字************** Autodesk.AutoCAD.Runtime.Exception:eInvalidInput 在Autodesk.AutoCAD.EditorInput.Editor.Command(Object []参数) 位于c:\ Users \ nickg \ Documents \ All Code \ autocad-adapter \ IOAutoCADHandler \ myCommands.cs中的AutoCAD_Adapter.MyCommands.MarkPosition():第186行 at Autodesk.AutoCAD.Runtime.CommandClass.InvokeWorker(MethodInfo mi,Object commandObject,Boolean bLispFunction) at 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()
答案 0 :(得分:1)
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"});
}
答案 1 :(得分:1)
使用 CommandFlags.Session
时,您无法使用ed.command()答案 2 :(得分:0)
使用此:
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.SendStringToExecute