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:
We are going to focus on one of the secondary command flags, the CommandFlags.Defun, in this post.
The CommandFlags.Defun indicates that the command can be invoked from LISP code as a parameter-less function.
We are going to create such a command specifying the CommandFlags.Defun. Here it is:
/// The command demonstrating the behavior of the Defun command flag.
[CommandMethod("CmdGroup1", "Command27", null, CommandFlags.Modal | CommandFlags.Defun, null, "Acad2027NetDemoAddinCS.chm", "Command27")]
public void Command27_Method()
Editor ed = AcadApplication.DocumentManager.MdiActiveDocument.Editor;
//TODO: add your code below.
catch (System.Exception ex)
Here are the command outputs for the command having the CommandFlags.Defun flag specified:
Unknown command "COMMAND27". Press F1 for help.
System.ArgumentException: Error binding to target method.
at System.Delegate.CreateDelegate(Type type, Object firstArgument,
MethodInfo method, Boolean throwOnBindFailure)
at Autodesk.AutoCAD.Runtime.CommandClass.InvokeWorker(MethodInfo mi, Object
commandObject, Boolean bLispFunction)
mi, Object commandObject, Boolean bLispFunction)
at Autodesk.AutoCAD.Runtime.PerDocumentCommandClass.Invoke(MethodInfo mi,
at Autodesk.AutoCAD.Runtime.CommandClass.CommandThunk.InvokeLisp(); error:
ADS request error
; error: no function definition: COMMAND24
As can be seen above, the Command27 cannot be invoked from the command line directly at all. The odd thing is that though the command is apparently supposed to be invoked as a lisp function like (command27) as demonstrated an exception is thrown out. The Command24 has no CommandFlags.Defun specified and it behaves as expected, being able to be invoked as a command but not as a LISP function.
In terms of the exception, let us make an educational guess here. The CommandFlags.Defun has been obsolete and the LispFunction Attribute is the replacement which we will introduce in detail in future. Another guess is that the CommandFlags.Defun may not be ready yet for AutoCAD .NET.
By the way, all the command definition code was generated automatically by using AutoCAD .NET Addin Wizard (AcadNetAddinWizard).
The leading edge AutoCAD .NET Addin Wizard (AcadNetAddinWizard) can create commands with any good combinations of all available CommandFlags optionally, flexibly, intelligently, and automatically.