- 积分
- 73549
- 明经币
- 个
- 注册时间
- 2001-6-7
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
发表于 2003-1-27 21:00:00
|
显示全部楼层
程序如内,你可以按你自己的意思随意更改过滤器
Private Sub ChangLayer()
On Error Resume Next
'建立选择集
Dim SSetObj As AcadSelectionSet
Set SSetObj = CreateSelectionSet
'建立过滤器,你可以通过更改过滤器来过滤出你所要的图元
Dim fType As Variant
Dim fData As Variant
BuildFilter fType, fdate, 0, "*LINE", 8, "A", 62, acRed, 43, "1"
'选择对象
SSetObj.Select acSelectionSetAll, , , fType, fData
If SSetObj.Count = 0 Then Exit Sub
'创建图层
Dim LayerObj As AcadLayer
Set LayerObj = CreateLayer("B")
'遍历每一图元更改图元的图层名称
Dim i As Integer
For i = 0 To SSetObj.Count - 1
SSetObj(i).Layer = LayerObj.Name
Next
Set LayerObj = Nothing
Set SSetObj = Nothing
End Sub
Public Sub BuildFilter(typeArray, dataArray, ParamArray gCodes())
Dim fType() As Integer, fData()
Dim index As Long, i As Long
index = LBound(gCodes) - 1
For i = LBound(gCodes) To UBound(gCodes) Step 2
index = index + 1
ReDim Preserve fType(0 To index)
ReDim Preserve fData(0 To index)
fType(index) = CInt(gCodes(i))
fData(index) = gCodes(i + 1)
Next
typeArray = fType: dataArray = fData
End Sub
Public Function CreateSelectionSet(Optional ssName As String = "ss") As AcadSelectionSet
Dim ss As AcadSelectionSet
On Error Resume Next
Set ss = ThisDrawing.SelectionSets(ssName)
If Err Then Set ss = ThisDrawing.SelectionSets.Add(ssName)
ss.Clear
Set CreateSelectionSet = ss
End Function
Public Function CreateLayer(ssLayerName As String) As AcadLayer
Set CreateLayer = ThisDrawing.Layers(ssLayerName)
If Err Then
Err.Clear
Set CreateLayer = ThisDrawing.Layers.Add(ssLayerName)
End If
End Function |
|