public class Commands
{
[CommandMethod("TEST", CommandFlags.Modal)]
public void Test()
{
Active.Editor.WriteMessage(" Get on with it !!");
}
/// <summary>SelectionSet with filter by Fence.</summary>
// This command does a simple selection and ignores all
// entities other than red circles.
[CommandMethod("SSetF", CommandFlags.Modal)]
public void SSGetFilterByFence()
{
// DxfCode.Start (equal to 0) - This is for 'Entity Name'
// DxfCode.Color is for ACI color - 1 = Red
TypedValue
[] filterValues
= new[] { new TypedValue
((int)DxfCode
.Start,
"CIRCLE"),
new TypedValue
((int)DxfCode
.Color,
1) };
SelectionFilter selectionFilter
= new SelectionFilter
(filterValues
);
Active.WriteMessage("\nFence point: (Enter when Done)");
Point3dCollection pointCollection = InteractivePolyLine.CollectPointsInteractive();
if (pointCollection.Count != 0) {
try {
SelectionSet ss;
PromptSelectionResult selectionResult = Active.Editor.SelectFence(pointCollection, selectionFilter);
if (selectionResult.Status == PromptStatus.OK) {
ss = selectionResult.Value;
if (ss != null) {
Active.WriteMessage($"\nThe SelectionSet has {ss.Count} entities.");
OutputCircleData(ss);
}
else {
Active.WriteMessage("\nThe SelectionSet has null value");
}
}
else { Active.WriteMessage("\nFence selection failed!"); }
}
catch (System.Exception ex) {
Active.WriteMessage(Environment.NewLine + ex.ToString());
}
}
}
/// <summary>SelectionSet with filter.</summary>
// This command does a simple selection and ignores all
// entities other than red circles.
// Use any of the conventional selection Keywords at the commandLine
[CommandMethod("SSetA", CommandFlags.Modal)]
public void SSGetFilterAnyMeans()
{
// DxfCode.Start (equal to 0) - This is for 'Entity Name'
// DxfCode.Color is for ACI color - 1 = Red
TypedValue
[] filterValues
= new[] { new TypedValue
((int)DxfCode
.Start,
"CIRCLE"),
new TypedValue
((int)DxfCode
.Color,
1) };
SelectionFilter selectionFilter
= new SelectionFilter
(filterValues
);
// Set the selection options
PromptSelectionOptions selectionOptions
= new PromptSelectionOptions
{ MessageForAdding = "Select Red Circles by Any means:",
AllowDuplicates = true
};
// Make the selection:
PromptSelectionResult selectionResult = Active.Editor.GetSelection(selectionOptions, selectionFilter);
if (!(selectionResult.Status == PromptStatus.OK))
return;
SelectionSet ss = selectionResult.Value;
OutputCircleData(ss);
}
/// <summary>Outputs the circle data.</summary>
/// <param name="ss">The SelectionSet of Circles.</param>
private void OutputCircleData(SelectionSet ss)
{
ObjectId[] idarray = ss.GetObjectIds();
// start a transaction
using (Transaction tr = Active.Database.TransactionManager.StartTransaction()) {
try {
foreach (var id in idarray) {
var circle = (Circle)tr.GetObject(id, OpenMode.ForRead, true);
Active.WriteMessage(
$"\nYou selected: {circle.GetType().FullName} with Radius = {circle.Radius }");
}
}
finally {
tr.Dispose();
}
}
}