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.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:
/// <summary>
/// The command demonstrating the behavior of the Defun command flag.
/// </summary>
[CommandMethod("CmdGroup1", "Command27", null, CommandFlags.Modal | CommandFlags.Defun, null, "Acad2027NetDemoAddinCS.chm", "Command27")]
public void Command27_Method()
{
Editor ed = AcadApplication.DocumentManager.MdiActiveDocument.Editor;
try
{
//TODO: add your code below.
ed.WriteMessage("Command27 ran.");
}
catch (System.Exception ex)
{
Debug.WriteLine(ex.ToString());
ed.WriteMessage(ex.ToString());
}
}
Here are the command outputs for the command having the CommandFlags.Defun flag specified:
Command: COMMAND27
Unknown command "COMMAND27". Press F1 for help.
Command: (command27)
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)
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.InvokeLisp(); error:
ADS request error
Command: COMMAND24
Command24 ran.
Command: (command24)
; 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 following illustration shows where the CommandFlags.Defun 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: |