AutoCAD .NET CommandFlags can be categorized into two major groups, the primary flags and secondary ones.
The primary CommandFlags have only two, Modal and Transparent.
The second CommandFlags 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.UsePickSet here, in this post.
The CommandFlags.UsePickSet indicates that the command will utilize the pre-selected entities if any before the command invocation in case entity (set) selection is required through calling the Editor.GetSelection() for example. If no entities are selected beforehand, the Editor.GetSelection() will behave as normal, asking users to select something.
If no CommandFlags.UsePickSet is specified for a command, it will clear out the pre-selected selection set if any and always prompts users to select some objects when the Editor.GetSelection() is called for example.
It sounds a bit abstract. Let us explain all these in a clear as crystal manner through some command examples and some corresponding outputs.
Here are the two simple command examples:
[CommandMethod("CmdGroup1", "Command1", null, CommandFlags.Modal | CommandFlags.UsePickSet, null, "Acad2012NetDemoAddinCS.chm", "Command1")]
public void Command1_Method()
{
Database db = HostApplicationServices.WorkingDatabase;
Editor ed = AcadApplication.DocumentManager.MdiActiveDocument.Editor;
try
{
using (Transaction tr = db.TransactionManager.StartTransaction())
{
//TODO: add your code below.
Debug.WriteLine("Command1 ran.");
ed.WriteMessage("Command1 ran.\n");
PromptSelectionResult selRes = ed.GetSelection();
if( selRes.Status == PromptStatus.OK )
{
Entity ent = tr.GetObject(selRes.Value.GetObjectIds()[0], OpenMode.ForRead) as Entity;
ed.WriteMessage(string.Format("UsePickSet: Layer name of the selected entity: {0}", ent.Layer));
}
tr.Commit();
}
}
catch (System.Exception ex)
{
Debug.WriteLine(ex.ToString());
ed.WriteMessage(ex.ToString());
}
}
[CommandMethod("CmdGroup1", "Command5", null, CommandFlags.Modal, null, "Acad2012NetDemoAddinCS.chm", "Command5")]
public void Command5_Method()
{
Database db = HostApplicationServices.WorkingDatabase;
Editor ed = AcadApplication.DocumentManager.MdiActiveDocument.Editor;
try
{
using (Transaction tr = db.TransactionManager.StartTransaction())
{
//TODO: add your code below.
Debug.WriteLine("Command5 ran.");
ed.WriteMessage("Command5 ran.\n");
PromptSelectionResult selRes = ed.GetSelection();
if (selRes.Status == PromptStatus.OK)
{
Entity ent = tr.GetObject(selRes.Value.GetObjectIds()[0], OpenMode.ForRead) as Entity;
ed.WriteMessage(string.Format("Not UsePickSet: Layer name of the selected entity: {0}", ent.Layer));
}
tr.Commit();
}
}
catch (System.Exception ex)
{
Debug.WriteLine(ex.ToString());
ed.WriteMessage(ex.ToString());
}
}
They are almost the same except for the CommandFlags.UsePickSet flag in the first command and command names for the distinction purpose only.
By the way, they were all generated automatically by using AutoCAD .NET Addin Wizard (AcadNetAddinWizard).
The following illustration shows where the UsePickSet command flag is on the wizard page:
Here are the command outputs exercising the typical scenarios regarding pre-selections and the two commands:
Command: CIRCLE
Specify center point for circle or [3P/2P/Ttr (tan tan radius)]:
Specify radius of circle or [Diameter]:
Command: SELECT
Select objects: 1 found
Select objects:
Command: COMMAND1
Command1 ran.
1 found
UsePickSet: Layer name of the selected entity: 0
Command: SELECT
Select objects: 1 found
Select objects:
Command: COMMAND5
Command5 ran.
Select objects: 1 found
Select objects:
Not UsePickSet: Layer name of the selected entity: 0
No words could be better descriptive than the above command outputs, I think.
Before finishing the topic, it may be worth of mentioning that it is not necessary to clear out the pre-selected selection set by ourselves supposing we do not have the need to change the set during the command execution. AutoCAD will clear it out automatically when the command finishes.
Of course, a way is provided if we do want to keep the pre-selected set still selected and maybe more like adding some more entities to the set. It is through specifying another command flag, more specifically, the CommandFlags.Redraw one.
We are going to talk about the CommandFlags.Redraw in the coming post. Stay tuned.
The leading edge AutoCAD .NET Addin Wizard (AcadNetAddinWizard) can create commands with any good combinations of these CommandFlags optionally, flexibly, intelligently, and automatically.
Recent Comments