Editor's Command method

Editor's Command method

Anonymous
Not applicable
2,057 Views
5 Replies
Message 1 of 6

Editor's Command method

Anonymous
Not applicable

I'm trying to create a button that, when pressed, marks the position of the drawing. Right now the method looks like this.

 

[CommandMethod("MARKPOS", CommandFlags.Session)]
public void MarkPosition()
{

    Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
    ed.Command("UNDO", "M");

}

 

However, when I try and execute the method I get the error pictured below and cannot determine why.

 

Capture.PNG

 

************** Exception Text **************
Autodesk.AutoCAD.Runtime.Exception: eInvalidInput
at Autodesk.AutoCAD.EditorInput.Editor.Command(Object[] parameter)
at AutoCAD_Adapter.MyCommands.MarkPosition() in c:\Users\nickg\Documents\All Code\autocad-adapter\IOAutoCADHandler\myCommands.cs:line 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)
at Autodesk.AutoCAD.Runtime.PerDocumentCommandClass.Invoke(MethodInfo mi, Boolean bLispFunction)
at Autodesk.AutoCAD.Runtime.CommandClass.CommandThunk.Invoke()

 

0 Likes
2,058 Views
5 Replies
Replies (5)
Message 2 of 6

Ajilal.Vijayan
Advisor
Advisor

Instead of using the editor to send command, try this

Autodesk.AutoCAD.Internal.Utils.SetUndoMark(True)

 

0 Likes
Message 3 of 6

Anonymous
Not applicable

Alright, is there a similar way to undo back to the mark?

0 Likes
Message 4 of 6

Ajilal.Vijayan
Advisor
Advisor

Yes, to undo back use this

Autodesk.AutoCAD.Internal.Utils.SetUndoMark(False)
0 Likes
Message 5 of 6

Anonymous
Not applicable

Are you sure? It doesn't seem like either Mark or Undo are working...

 

public static void MarkPosition()
{
Utils.SetUndoMark(true);
ed.WriteMessage("Undo Mark Set");
}

/// <summary>
/// Method to step AutoCAD back to undo mark

/// </summary>
public static void BigUndo()
{
Utils.SetUndoMark(false);
ed.WriteMessage("Undo to Previous Mark Complete");
}

0 Likes
Message 6 of 6

Anonymous
Not applicable

works for me..  (the false settings doesn't trigger the undo event, just closes the undo set)  You just have to call undo after closing it?

0 Likes