选择筛选器可以包含多个属性或对象的筛选条件。您可以通过声明一个包含足够元素来表示每个筛选条件的数组来定义要筛选的条件总数。 选择满足两个条件的对象以下示例指定用于筛选所选对象的两个条件:对象必须是圆形,并且必须位于图层 0 上。 VB.NETImports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
<CommandMethod("FilterBlueCircleOnLayer0")> _
Public Sub FilterBlueCircleOnLayer0()
'' Get the current document editor
Dim acDocEd As Editor = Application.DocumentManager.MdiActiveDocument.Editor
'' Create a TypedValue array to define the filter criteria
Dim acTypValAr(2) As TypedValue
acTypValAr.SetValue(New TypedValue(DxfCode.Color, 5), 0)
acTypValAr.SetValue(New TypedValue(DxfCode.Start, "CIRCLE"), 1)
acTypValAr.SetValue(New TypedValue(DxfCode.LayerName, "0"), 2)
'' Assign the filter criteria to a SelectionFilter object
Dim acSelFtr As SelectionFilter = New SelectionFilter(acTypValAr)
'' Request for objects to be selected in the drawing area
Dim acSSPrompt As PromptSelectionResult
acSSPrompt = acDocEd.GetSelection(acSelFtr)
'' If the prompt status is OK, objects were selected
If acSSPrompt.Status = PromptStatus.OK Then
Dim acSSet As SelectionSet = acSSPrompt.Value
Application.ShowAlertDialog("Number of objects selected: " & _
acSSet.Count.ToString())
Else
Application.ShowAlertDialog("Number of objects selected: 0")
End If
End Sub
C#using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
[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, "0"), 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");
}
}
VBA/ActiveX 代码参考Sub FilterBlueCircleOnLayer0()
Dim sset As AcadSelectionSet
Set sset = ThisDrawing.SelectionSets.Add("SS1")
' Define the filter list, only blue Circle objects
' on layer 0
Dim FilterType(2) As Integer
Dim FilterData(2) As Variant
FilterType(0) = 62: FilterData(0) = 3
FilterType(1) = 0: FilterData(1) = "Circle"
FilterType(2) = 8: FilterData(2) = "0"
' Prompt the user to select objects
' and add them to the selection set
sset.SelectOnScreen FilterType, FilterData
MsgBox "Number of objects selected: " & sset.Count
' Remove the selection set at the end
sset.Delete
End Sub
相关概念父主题: |
|Archiver|CAD开发者社区
( 苏ICP备2022047690号-1 苏公网安备32011402011833)
GMT+8, 2025-10-29 12:17
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.