指定多个选择条件时,AutoCAD 假定所选对象必须满足每个条件。您可以通过其他方式限定您的标准。对于数值项目,可以指定关系运算(例如,圆的半径必须大于或等于5.0)。对于所有项目,您可以指定逻辑操作(例如,或)。TextMText 使用 -4 DXF 代码或常量来指示选择过滤器中的关系运算符。运算符表示为字符串。下表显示了允许的关系运算符。DxfCode.Operator
选择过滤器中的逻辑运算符也由 -4 组码或常量指示,运算符是字符串,但运算符必须配对。开盘运算符前面是小于号 (<),收盘运算符后跟大于号 (>)。下表列出了选择集过滤中允许的逻辑运算符。DxfCode.Operator
选择半径大于或等于 5.0 的圆下面的示例选择半径大于或等于 5.0 的圆。 VB.NETImports Autodesk.AutoCAD.Runtime Imports Autodesk.AutoCAD.ApplicationServices Imports Autodesk.AutoCAD.DatabaseServices Imports Autodesk.AutoCAD.EditorInput <CommandMethod("FilterRelational")> _ Public Sub FilterRelational() '' 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.Start, "CIRCLE"), 0) acTypValAr.SetValue(New TypedValue(DxfCode.Operator, ">="), 1) acTypValAr.SetValue(New TypedValue(40, 5), 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("FilterRelational")] public static void FilterRelational() { // 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.Start, "CIRCLE"), 0); acTypValAr.SetValue(new TypedValue((int)DxfCode.Operator, ">="), 1); acTypValAr.SetValue(new TypedValue(40, 5), 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 Code ReferenceSub FilterRelational() Dim sset As AcadSelectionSet Dim FilterType(2) As Integer Dim FilterData(2) As Variant Set sset = ThisDrawing.SelectionSets.Add("SS1") FilterType(0) = 0: FilterData(0) = "Circle" FilterType(1) = -4: FilterData(1) = ">=" FilterType(2) = 40: FilterData(2) = 5# sset.SelectOnScreen FilterType, FilterData MsgBox "Number of objects selected: " & sset.Count ' Remove the selection set at the end sset.Delete End Sub Select either Text or MTextThe following example specifies that either or objects can be selected. TextMText VB.NETImports Autodesk.AutoCAD.Runtime Imports Autodesk.AutoCAD.ApplicationServices Imports Autodesk.AutoCAD.DatabaseServices Imports Autodesk.AutoCAD.EditorInput <CommandMethod("FilterForText")> _ Public Sub FilterForText() '' Get the current document editor Dim acDocEd As Editor = Application.DocumentManager.MdiActiveDocument.Editor '' Create a TypedValue array to define the filter criteria Dim acTypValAr(3) As TypedValue acTypValAr.SetValue(New TypedValue(DxfCode.Operator, "<or"), 0) acTypValAr.SetValue(New TypedValue(DxfCode.Start, "TEXT"), 1) acTypValAr.SetValue(New TypedValue(DxfCode.Start, "MTEXT"), 2) acTypValAr.SetValue(New TypedValue(DxfCode.Operator, "or>"), 3) '' 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("FilterForText")] public static void FilterForText() { // Get the current document editor Editor acDocEd = Application.DocumentManager.MdiActiveDocument.Editor; // Create a TypedValue array to define the filter criteria TypedValue[] acTypValAr = new TypedValue[4]; acTypValAr.SetValue(new TypedValue((int)DxfCode.Operator, "<or"), 0); acTypValAr.SetValue(new TypedValue((int)DxfCode.Start, "TEXT"), 1); acTypValAr.SetValue(new TypedValue((int)DxfCode.Start, "MTEXT"), 2); acTypValAr.SetValue(new TypedValue((int)DxfCode.Operator, "or>"), 3); // 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 FilterForText() Dim sset As AcadSelectionSet Dim FilterType(3) As Integer Dim FilterData(3) As Variant Set sset = ThisDrawing.SelectionSets.Add("SS1") FilterType(0) = -4: FilterData(0) = "<or" FilterType(1) = 0: FilterData(1) = "TEXT" FilterType(2) = 0: FilterData(2) = "MTEXT" FilterType(3) = -4: FilterData(3) = "or>" 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 )
GMT+8, 2024-5-19 13:11
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.