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 two of the secondary command flags in this post, CommandFlags.ActionMacro and CommandFlags.NoActionRecording.
The command flag CommandFlags.ActionMacro indicates that the command will be recorded as an Action Macro. The command flag CommandFlags.NoActionRecording indicates that the actions of the command will not be recorded. Though AutoCAD must have provided a default behavior regarding command actions to be recorded or not for commands that specifies none of the two command flags, CommandFlags.ActionMacro and CommandFlags.NoActionRecording, it seems we’d better specify one of them for commands as far as Action Macro is concerned.
There might be some system variable to control the default behavior of those commands that do not specify either CommandFlags.ActionMacro or CommandFlags.NoActionRecording but it is not the major concern of this article. Another pending stuff is what will happen if both CommandFlags.ActionMacro and CommandFlags.NoActionRecording are specified for a single command. Let’s make an educational guess again here. It will behave exactly as none of the two is specified. Please feel free to give it a try if anybody is interested.
We are going to create two sample commands to compare the different behavior between specifying CommandFlags.ActionMacro and CommandFlags.NoActionRecording. Here they are:
/// <summary>
/// The command demonstrating the behavior of the NoActionRecording command flag.
/// </summary>
[CommandMethod("CmdGroup1", "Command21", null, CommandFlags.Modal | CommandFlags.NoActionRecording, null, "Acad2021NetDemoAddinCS.chm", "Command21")]
public void Command21_Method()
{
Editor ed = AcadApplication.DocumentManager.MdiActiveDocument.Editor;
try
{
//TODO: add your code below.
ed.WriteMessage("Command21 ran.");
}
catch (System.Exception ex)
{
Debug.WriteLine(ex.ToString());
ed.WriteMessage(ex.ToString());
}
}
/// <summary>
/// The command demonstrating the behavior of the ActionMacro command flag.
/// </summary>
[CommandMethod("CmdGroup1", "Command20", null, CommandFlags.Modal | CommandFlags.ActionMacro, null, "Acad2020NetDemoAddinCS.chm", "Command20")]
public void Command20_Method()
{
Editor ed = AcadApplication.DocumentManager.MdiActiveDocument.Editor;
try
{
//TODO: add your code below.
ed.WriteMessage("Command20 ran.");
}
catch (System.Exception ex)
{
Debug.WriteLine(ex.ToString());
ed.WriteMessage(ex.ToString());
}
}
Here are the command outputs and the Action Trees for the two commands:
As can be noticed, the Command20 which specifies the CommandFlags.NoActionRecording is not recorded in the Action Macro by the ActRecrod command, but the Command21 does as it specifies the CommandFlags.ActionMacro instead. All are clear enough and as expected, aren’t they?
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.ActionMacro and CommandFlags.NoActionRecording command flag are 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.
Just an FYI for you & passers-by - neither of these flags are supported in Acad 2007.
Great blog & I like the Wizard. Very nice work
Posted by: CAD bloke | 09/06/2012 at 09:06 AM
Ewen, thank you very much for the info. The wizard needs a bit adjustments and some more testing work in old versions of AutoCAD, obviously. We have kept it recorded.
Also very glad to hear you like the wizard and the blog.
Posted by: Spiderinnet1 | 09/06/2012 at 03:27 PM
Hi Spider, I also found that NoInferConstraint & TempShowDynDimension would not compile in 2007 & 2010, FYI.
I am in the middle of putting together a template to build the same source code into projects for various versions of AutoCAD, as well as NanoCAD and whatever else I find with a .NET API. I elaborated on it a bit at http://www.theswamp.org/index.php?topic=41850.msg472902#msg472902
I have projects for AutoCAD 2007, 2010 & 2013. When I build all of them it's easy to see which version doesn't like the source code.
Posted by: CAD bloke | 09/08/2012 at 11:01 AM
Ewen, thanks again for pointing it out. Got it recorded as well.
It’s a nice strategy to build the same source for different AutoCAD versions.
Posted by: Spiderinnet1 | 09/08/2012 at 04:06 PM