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.NoHistory, in this post.
The CommandFlags.NoHistory indicates that the command will not be added into the command history (Recent Commands) list and it cannot be repeated by simply pressing the enter key or choosing it from the context menu.
We are going to create a few sample commands to compare the different behavior between specifying the CommandFlags.NoHistory and not. Here is the one that has the CommandFlags.NoHistory specified:
/// <summary>
/// The command demonstrating the behavior of the NoHistory command flag.
/// </summary>
[CommandMethod("CmdGroup1", "Command22", null, CommandFlags.Modal | CommandFlags.NoHistory, null, "Acad2022NetDemoAddinCS.chm", "Command22")]
public void Command22_Method()
{
Editor ed = AcadApplication.DocumentManager.MdiActiveDocument.Editor;
try
{
//TODO: add your code below.
ed.WriteMessage("Command22 ran.");
}
catch (System.Exception ex)
{
Debug.WriteLine(ex.ToString());
ed.WriteMessage(ex.ToString());
}
}
In terms of the Command20 and Command21 which had not the CommandFlags.NoHistory flag specified have been introduced in earlier posts. Please find their sample code there.
After the two commands ran, we found that they were added to the Recent Commands history list:
After the Command22 ran however, because the CommandFlags.NoHistory flag was specified for the command it did not appear in the Recent Commands list:
After the ENTER key was simply pressed, the Command21 which ran right before the Command22 would be repeated instead of the Command22 itself.
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.NoHistory 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.
Posted by: |