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 flag, the CommandFlags.DocExclusiveLock, in this post.
The CommandFlags.DocExclusiveLock indicates that the command will have the Exclusive Write privilege to the current document that the command is running in. The default privilege is Share Write, or just Write.
We are going to create two sample commands to compare the different behaviour between specifying the CommandFlags.DocExclusiveLock and not. Here are they:
/// <summary>
/// The command demonstrating the behavior of without the DocExclusiveLock command flag.
/// </summary>
[CommandMethod("CmdGroup1", "Command13", null, CommandFlags.Modal, null, "Acad2012NetDemoAddinCS.chm", "Command13")]
public void Command13_Method()
{
Editor ed = AcadApplication.DocumentManager.MdiActiveDocument.Editor;
try
{
ed.WriteMessage(AcadApplication.DocumentManager.MdiActiveDocument.LockMode().ToString());
}
catch (System.Exception ex)
{
Debug.WriteLine(ex.ToString());
ed.WriteMessage(ex.ToString());
}
}
/// <summary>
/// The command demonstrating the behavior of the DocExclusiveLock command flag.
/// </summary>
[CommandMethod("CmdGroup1", "Command12", null, CommandFlags.Modal | CommandFlags.DocExclusiveLock, null, "Acad2012NetDemoAddinCS.chm", "Command12")]
public void Command12_Method()
{
Editor ed = AcadApplication.DocumentManager.MdiActiveDocument.Editor;
try
{
ed.WriteMessage(AcadApplication.DocumentManager.MdiActiveDocument.LockMode().ToString());
}
catch (System.Exception ex)
{
Debug.WriteLine(ex.ToString());
ed.WriteMessage(ex.ToString());
}
}
It is also demonstrated how to check the lock mode of the active document though calling the Document.LockMode method. Here are the command outputs for the two commands:
Command: Command13
Write
Command: Command12
ExclusiveWrite
The CommandFlags.DocExclusiveLock command flag provides a static way to set the document lock at design time. The Document.LockDocument() method can be used to set the document lock on the fly.
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.DocExclusiveLock 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