AutoCAD .NET Command Flags can be categorized into two major groups, the primary flags and secondary ones.
The primary Command Flags have only two, Modal and Transparent.
The second Command Flags have quite a few:
UsePickSet
Redraw
Session
Interruptible
DocExclusiveLock
DocReadLock
NoInternalLock
NoPaperSpace
NoTileMode
NoPerspective
NoBlockEditor
ActionMacro
NoActionRecording
NoHistory
NoMultiple
NoUndoMarker
NoNewStack
NoOem
Defun
InProgress
Undefined
We are going to focus on one of the secondary command flags, the CommandFlags.NoUndoMarker, in this post.
The CommandFlags.NoUndoMarker indicates that the command will not be marked for the UNDO mechanism, more specifically the UNDO command one step back will have nothing to do with the command even if it is run right before the UNDO.
We are going to create such a command specifying the CommandFlags.NoUndoMarker. Here it is:
/// <summary>
/// The command demonstrating the behavior of the NoUndoMarker command flag.
/// </summary>
[CommandMethod("CmdGroup1", "Command24", null, CommandFlags.Modal | CommandFlags.NoUndoMarker, null, "Acad2024NetDemoAddinCS.chm", "Command24")]
public void Command24_Method()
{
Editor ed = AcadApplication.DocumentManager.MdiActiveDocument.Editor;
try
{
//TODO: add your code below.
ed.WriteMessage("Command24 ran.");
}
catch (System.Exception ex)
{
Debug.WriteLine(ex.ToString());
ed.WriteMessage(ex.ToString());
}
}
Here are the command outputs for the command and another command not having the CommandFlags.NoUndoMarker flag specified:
Command: LINE
Specify first point:
Specify next point or [Undo]:
Specify next point or [Undo]:
Command: COMMAND24
Command24 ran.
Command: UNDO
Current settings: Auto = On, Control = All, Combine = Yes, Layer = Yes
Enter the number of operations to undo or [Auto/Control/BEgin/End/Mark/Back]
<1>:
LINE
Command: COMMAND22
Command22 ran.
Command: UNDO
Current settings: Auto = On, Control = All, Combine = Yes, Layer = Yes
Enter the number of operations to undo or [Auto/Control/BEgin/End/Mark/Back]
<1>:
COMMAND22
As can be seen above, the Command24 cannot be UNDOed. Instead, the command run right before it will be UNDOed. But the Command22 which does not have the flag CommandFlags.NoUndoMarker specified will behave as usual, the UNDO command being able to successfully look after it.
By the way, all the command definition code was generated automatically by using AutoCAD .NET Addin Wizard (AcadNetAddinWizard).
The following illustration shows where the CommandFlags.NoUndoMarker command flag is on the wizard page:
The leading edge AutoCAD .NET Addin Wizard (AcadNetAddinWizard) can create commands with any good combinations of all available CommandFlags optionally, flexibly, intelligently, and automatically.
Recent Comments