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.DocReadLock, in this post.
The CommandFlags.DocReadLock indicates that the command will have the Document Read 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.DocReadLock and not. Here are they:
/// <summary>
/// The command demonstrating the behavior of without the DocReadLock 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 DocReadLock command flag.
/// </summary>
[CommandMethod("CmdGroup1", "Command14", null, CommandFlags.Modal | CommandFlags.DocReadLock, null, "Acad2014NetDemoAddinCS.chm", "Command14")]
public void Command14_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: Command14
NotLocked
So the CommandFlags.DocReadLock equals to DocumentLockMode.NotLocked. The CommandFlags.DocReadLock 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.DocReadLock 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