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 as they are related to each other, the CommandFlags.NoPaperSpace and the CommandFlags.NoTileMode, in this post.
Before we go deep, let’s clarify some concepts first. In AutoCAD, we have to drawing spaces that we can work in, model space and paper space. An AutoCAD system variable controls where we are, the TileMode.
When it is 0 we are in the paper space, indicating that the paper space is not tillable; if TileMode 1, model space, meaning the model space is able to be tiled. So TileMode and DrawingSpace point to pretty much the same thing.
In terms of the CommandFlags.NoPaperSpace and the CommandFlags.NoTileMode command flags, NoPaperSpace indicates that the command is not permitted in the paper space (with TileMode as 0); NoTileMode tells us that the command is not runnable in the model space (with TileModel as 1).
I believe with a table presented as follows things would be clear enough:
TileMode Drawing Space CommandFlags
0 PaperSpace NoTileMode
1 ModelSpace NoPaperSpace
Of course, confusions could be less if the two command flags are named as PaperSpaceOnly and ModelSpaceOnly, or TileMode0 and TileMode1, or rename the NoPaperSpace as TileMode, but that is not the real concern of the article.
We are going to create two sample commands to compare the different behavior between specifying the CommandFlags.NoPaperSpace and the CommandFlags.NoTileMode. Here are they:
/// <summary>
/// The command demonstrating the behavior of the NoTileMode command flag.
/// </summary>
[CommandMethod("CmdGroup1", "Command17", null, CommandFlags.Modal | CommandFlags.NoTileMode, null, "Acad2017NetDemoAddinCS.chm", "Command17")]
public void Command17_Method()
{
Editor ed = AcadApplication.DocumentManager.MdiActiveDocument.Editor;
try
{
//TODO: add your code below.
Debug.WriteLine("Command17 ran.");
}
catch (System.Exception ex)
{
Debug.WriteLine(ex.ToString());
ed.WriteMessage(ex.ToString());
}
}
/// <summary>
/// The command demonstrating the behavior of the NoPaperSpace command flag.
/// </summary>
[CommandMethod("CmdGroup1", "Command16", null, CommandFlags.Modal | CommandFlags.NoPaperSpace, null, "Acad2016NetDemoAddinCS.chm", "Command16")]
public void Command16_Method()
{
Editor ed = AcadApplication.DocumentManager.MdiActiveDocument.Editor;
try
{
//TODO: add your code below.
Debug.WriteLine("Command16 ran.");
}
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: TILEMODE
Enter new value for TILEMODE <1>: 1
Command: COMMAND16
Command16 ran.
Command: COMMAND17
** Command not allowed in Model Tab **
Command: TILEMODE
Enter new value for TILEMODE <1>: 0
Regenerating layout.
Regenerating layout.
Regenerating model - caching viewports.
Command: COMMAND16
** Command only valid in Model space **
Command: COMMAND17
Command17 ran.
By the way, all the command definition code was generated automatically by using AutoCAD .NET Addin Wizard (AcadNetAddinWizard).
The following illustration shows where the the CommandFlags.NoPaperSpace and the CommandFlags.NoTileMode command flags 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.
Posted by: |