Skip to content

Commit

Permalink
muti filter rule
Browse files Browse the repository at this point in the history
  • Loading branch information
chuongmep committed May 22, 2022
1 parent 54ec86c commit 9c09059
Show file tree
Hide file tree
Showing 4 changed files with 174 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ Thumbs.db
*.ide-wal
*.dll
*.suo
*.dwl
*.dwl2
[Bb]in
[Dd]ebug*/
*.lib
Expand Down
76 changes: 76 additions & 0 deletions Test/Selection/MergeSelection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
using Autodesk.AutoCAD.ApplicationServices.Core;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;

namespace Test;

public class MergeSelection
{
[CommandMethod("MergeSelectionSets")]
public static void MergeSelectionSets()
{
// Get the current document editor
Editor acDocEd = Application.DocumentManager.MdiActiveDocument.Editor;
// Request for objects to be selected in the drawing area

PromptSelectionResult acSSPrompt;

acSSPrompt = acDocEd.GetSelection();
SelectionSet acSSet1;

ObjectIdCollection acObjIdColl = new ObjectIdCollection();
// If the prompt status is OK, objects were selected

if (acSSPrompt.Status == PromptStatus.OK)

{
// Get the selected objects

acSSet1 = acSSPrompt.Value;
// Append the selected objects to the ObjectIdCollection

acObjIdColl = new ObjectIdCollection(acSSet1.GetObjectIds());
}
// Request for objects to be selected in the drawing area

acSSPrompt = acDocEd.GetSelection();
SelectionSet acSSet2;


// If the prompt status is OK, objects were selected

if (acSSPrompt.Status == PromptStatus.OK)

{
acSSet2 = acSSPrompt.Value;


// Check the size of the ObjectIdCollection, if zero, then initialize it

if (acObjIdColl.Count == 0)

{
acObjIdColl = new ObjectIdCollection(acSSet2.GetObjectIds());
}

else

{
// Step through the second selection set

foreach (ObjectId acObjId in acSSet2.GetObjectIds())

{
// Add each object id to the ObjectIdCollection

acObjIdColl.Add(acObjId);
}
}
}


Application.ShowAlertDialog("Number of objects selected: " +
acObjIdColl.Count.ToString());
}
}
50 changes: 50 additions & 0 deletions Test/Selection/MultiFilterRule.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using Autodesk.AutoCAD.ApplicationServices.Core;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;

namespace Test;

public class MultiFilterRule
{
[CommandMethod("FilterBlueCircleOnLayer0")]
public static void FilterBlueCircleOnLayer0()

{
// Get the current document editor

Editor acDocEd = Application.DocumentManager.MdiActiveDocument.Editor;
// Create a TypedValue array to define the filter criteria

TypedValue[] acTypValAr = new TypedValue[3];

acTypValAr.SetValue(new TypedValue((int) DxfCode.Color, 5), 0);

acTypValAr.SetValue(new TypedValue((int) DxfCode.Start, "CIRCLE"), 1);

acTypValAr.SetValue(new TypedValue((int) DxfCode.LayerName, "Layer2"), 2);


// Assign the filter criteria to a SelectionFilter object
SelectionFilter acSelFtr = new SelectionFilter(acTypValAr);
// Request for objects to be selected in the drawing area

PromptSelectionResult acSSPrompt;

acSSPrompt = acDocEd.GetSelection(acSelFtr);
// If the prompt status is OK, objects were selected

if (acSSPrompt.Status == PromptStatus.OK)
{
SelectionSet acSSet = acSSPrompt.Value;
Application.ShowAlertDialog("Number of objects selected: " +
acSSet.Count.ToString());
}

else

{
Application.ShowAlertDialog("Number of objects selected: 0");
}
}
}
46 changes: 46 additions & 0 deletions Test/Selection/SelectionFilters.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using Autodesk.AutoCAD.ApplicationServices.Core;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;

namespace Test;

public class SelectionFilters
{
[CommandMethod("FilterSelectionSet")]
public static void FilterSelectionSet()

{
// Get the current document editor

Editor acDocEd = Application.DocumentManager.MdiActiveDocument.Editor;
// Create a TypedValue array to define the filter criteria

TypedValue[] acTypValAr = new TypedValue[1];

acTypValAr.SetValue(new TypedValue((int) DxfCode.Start, "CIRCLE"), 0);
// Assign the filter criteria to a SelectionFilter object

SelectionFilter acSelFtr = new SelectionFilter(acTypValAr);
// Request for objects to be selected in the drawing area

PromptSelectionResult acSSPrompt;

acSSPrompt = acDocEd.GetSelection(acSelFtr);


// If the prompt status is OK, objects were selected

if (acSSPrompt.Status == PromptStatus.OK)

{
SelectionSet acSSet = acSSPrompt.Value;

Application.ShowAlertDialog("Number of objects selected: " + acSSet.Count.ToString());
}
else
{
Application.ShowAlertDialog("Number of objects selected: 0");
}
}
}

0 comments on commit 9c09059

Please sign in to comment.