Sub Test01() ''测试多条件组码
Dim i, j, n, k, k0, k1 As Integer
Dim x0, y0, x, y As Double
Dim acSSet As AcadSelectionSet
Dim acEnt As AcadEntity
Dim Point(0 To 2) As Double
''在VBA中的正确定义方法
Dim Ftype(0 To 6) As Integer
Dim Fdata(0 To 6) As Variant
Dim Point1, Point2 As Variant
''在框行范围内,选择 勘察图层中 的 多段线 or 二维多段线
‘’ 这个程序经多方试验,终于成功
‘’ 不想其它程序员走弯路,费脑筋,于是分享出来
‘’ 程序提示框选范围
Point1 = ThisDrawing.Utility.GetPoint(, "框选标注范围,第一个点:")
Point2 = ThisDrawing.Utility.GetCorner(Point1, "框选范围,第二个点:")
For Each acSSet In ThisDrawing.SelectionSets
If acSSet.Name = "user1" Then
acSSet.Delete
Exit For '' 这个位置的改进很关键,因为当你删除一个选择集后,若整个选择集为空后,Next 语句会导致错误!
End If
Next acSSet
Set acSSet = ThisDrawing.SelectionSets.Add("user1")
'' 以下是重点,网上的资料很少,经过多次踩坑才得以通过!
'' AND , OR 的组合用法
Ftype(0) = -4: Fdata(0) = "<AND"
Ftype(1) = 8: Fdata(1) = "00勘察布孔边线"
Ftype(2) = -4: Fdata(2) = "<OR"
Ftype(3) = 0: Fdata(3) = "LWPolyLine"
Ftype(4) = 0: Fdata(4) = "PolyLine"
Ftype(5) = -4: Fdata(5) = "OR>"
Ftype(6) = -4: Fdata(6) = "AND>"
‘’ 多段线在选择集中正确的名称,搞得人有点晕哟
‘’ debug.print的名称 AcDbPolyline , AcDb2dPolyline
‘’ 实际组码中的名称 LWPolyLine , PolyLine
acSSet.Select acSelectionSetWindow, Point1, Point2, Ftype, Fdata
For Each acEnt In acSSet
Debug.Print acEnt.ObjectName
Next
MsgBox “Ok~”
End Sub