根据AutoCAD2004 VBA的说明,Select方法的描述为: object.Select Mode[, Point1][, Point2][, FilterType][, FilterData] 如选择所有的圆,可以使用如下代码: Dim gpCode(0) As Integer Dim dataValue(0) As Variant gpCode(0) = 0
dataValue(0) = \
ssetObj.Select acSelectionSetAll, , , gpCode, dataValue
我的问题就是,如果要选择其它的对象,如何设置FilterType, FilterData?比如对象为 Ployline时。
哪位大侠能不能给一个关于此类设置的总结啊? ============================= Mode
============================= acSelectionSetWindow = 0
Selects all objects completely inside a rectangular area whose corners are defined by Point1 and Point2. And meets condition of FilterType and FilterData
acSelectionSetCrossing = 1
Selects objects within and crossing a rectangular area whose corners are defined by Point1 and Point2.And meets condition of FilterType and FilterData acSelectionSetFence = 2
Selects all objects completely inside Fence area whose are defined by Points. And meets condition of FilterType and FilterData acSelectionSetPrevious = 3
Selects the most recent selection set. This mode is ignored if you switch between paper space and model space and attempt to use the selection set. And meets condition of FilterType and FilterData acSelectionSetLast = 4
Selects the most recently created visible objects. And meets condition of FilterType and FilterData acSelectionSetAll = 5
Selects all objects. And meets condition of FilterType and FilterData acSelectionSetWindowPolygon = 6 acSelectionSetCrossingPolygon = 7
***************************************************************************** 参考:
'------------------------------------------------------------------ Option Explicit
'------------------------------------------------------------------ Public Sub Sample()
On Error GoTo ERROR_HANDLER Dim ssetObj As AcadSelectionSet
Set ssetObj = CreateSSet(\
Dim mode As Integer mode = acSelectionSetAll
Dim gpCode(0 To 10) As Integer Dim dataValue(0 To 10) As Variant
gpCode(0) = -4
dataValue(0) = \ gpCode(1) = -4
dataValue(1) = \ gpCode(2) = 0
dataValue(2) = \ gpCode(3) = -4
dataValue(3) = \
gpCode(4) = -4
dataValue(4) = \ gpCode(5) = 0
dataValue(5) = \YLINE\ gpCode(6) = -4
dataValue(6) = \
gpCode(7) = -4
dataValue(7) = \ gpCode(8) = 0
dataValue(8) = \YLINE\ gpCode(9) = -4
dataValue(9) = \
gpCode(10) = -4
dataValue(10) = \
Dim groupCode As Variant, dataCode As Variant groupCode = gpCode dataCode = dataValue
ssetObj.Select mode, , , groupCode, dataCode
MsgBox ssetObj.Count
Exit Sub
ERROR_HANDLER:
Debug.Print \ Err.Description End Sub
'------------------------------------------------------------------ ' 创建选择集
'------------------------------------------------------------------
Private Function CreateSSet(ByVal name As String) As AcadSelectionSet On Error GoTo ERR_HANDLER
Dim ssetObj As AcadSelectionSet Dim SSetColl As AcadSelectionSets
Set SSetColl = ThisDrawing.SelectionSets
Dim index As Integer Dim found As Boolean
found = False
For index = 0 To SSetColl.Count - 1 Set ssetObj = SSetColl.Item(index)
If StrComp(ssetObj.name, name, 1) = 0 Then found = True Exit For End If Next
If Not (found) Then
Set ssetObj = SSetColl.Add(name) Else
ssetObj.Clear End If
Set CreateSSet = ssetObj
Exit Function ERR_HANDLER:
Debug.Print \ Resume ERR_END
ERR_END: End Function
*********************************************************************** 过滤器列表由成对的参数组成。第一个参数标识过滤器的类型(例如对象),第二个参数指
定
要过滤的值(例如圆)。过滤器类型是指定使用哪种过滤器的 DXF 组码。下面列出了一些最常
用的过滤器类型。
================================================================================
常用过滤器的 DXF 组码 <请详查DXF手册>
-------------------------------------------------------------------------------- DXF组码 过滤器类型 缺省值
-------------------------------------------------------------------------------- -1 实体名称(随图档的开启而不同) 不可省略 -------------------------------------------------------------------------------- 0 对象类型(字符串)
例如“Line”、“Circle”、“Arc”等。 不可省略 -------------------------------------------------------------------------------- 2 对象名(字符串) 不可省略 命名对象的表(给定)名称。
-------------------------------------------------------------------------------- 5 处理码 不可省略
--------------------------------------------------------------------------------
6 线型名称(若线型不为bylayer,此群码值会出现) bylayer -------------------------------------------------------------------------------- 8 图层名(字符串) 0 例如“图层 0”。
-------------------------------------------------------------------------------- 48 线型比例(选择) 1.0
-------------------------------------------------------------------------------- 60 对象可见性(整数)
使用 0 = 可见,1 = 不可见。
-------------------------------------------------------------------------------- 62 颜色编号(整数) bylayer 范围 0 到 256 内的数字索引值。
零表示 BYBLOCK。256表示BYLAYER。 负值表示图层被关闭。
-------------------------------------------------------------------------------- 67 模型/图纸空间标识符(整数) 0 使用 0 或省略=模型空间,1=图纸空间。
================================================================================
物件是CIRCLE OR 物件是LINE FilterData
(物件是CIRCLE OR 物件是LINE) AND 圖層位於DIM層
FilterData DIM AND> FilterType -4 -4 0 0 -4 8 -4
物件是CIRCLE OR 物件是LINE) AND NOT(圖層位於DIM層) FilterData
过滤器参数声明为数组,过滤器类型声明为整数,过滤器值声明为变量。每个过滤器类型都必
须与过滤器值成对出现。例如:
FilterType(0) = 0 ' 表示过滤器是对象类型FilterData(0) = \' 表示对象类型 是“Circle”
以下代码指定两个条件:对象必须是圆,并且必须在图层 0 上。代码将 FilterType 和 FilterData 声明为两个元素的数组,并将每个条件指定给一个元素:
Sub Ch4_FilterBlueCircleOnLayer0() Dim sstext As AcadSelectionSet Dim FilterType(1) As Integer Dim FilterData(1) As Variant
Set sstext = ThisDrawing.SelectionSets.Add(\ FilterType(0) = 0
FilterData(0) = \ FilterType(1) = 8 FilterData(1) = \
sstext.SelectOnScreen FilterType, FilterData End Sub
在指定多个选择条件时,AutoCAD 会假设选定的对象必须符合每一个条件。但用户可以按照其
他方式来指定条件。对于数字项,用户可以指定关系运算(例如,圆的半径必须大于或等于 5.0);对于所有项,用户可以指定逻辑运算(例如 Text 或 Mtext)。
使用 -4 DXF 组码来指示过滤器规格中的关系运算符。以字符串的形式来指定运算符。下表显
示了可以使用的关系运算符:
=========================== 选择集过滤器列表的关系运算符 -------------------------- 运算符 说明
--------------------------
\任何情况(总为真) -------------------------- \等于
-------------------------- \不等于