- 积分
- 463
- 明经币
- 个
- 注册时间
- 2012-9-11
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
我想实现,通过点选一个实体,然后根据它的颜色,全部选中途中相同颜色的实体对象。我是通过读取TrueColor的ColorIndex属性来获取颜色索引值。但是有个问题了。当颜色值为256,既为bylayer类型时,就搞不定了。这种情况应该怎么做呢。谢谢
'************************************************************************************
'按颜色选择相同颜色的实体对象:************************************
'************************************************************************************
Sub PublicSub333()
On Error GoTo errhandle
ThisDrawing.Utility.Prompt vbCrLf & "当前命令:颜色选择" & vbCrLf
' Exit Sub
Dim i As Long
Dim k As Long
Dim entityObj As AcadEntity '实体变量
Dim nColor As Integer '颜色值
'创建空白选择集
Dim SelSet As AcadSelectionSet
If ThisDrawing.SelectionSets.Count > 0 Then '如果选择集已经存在,删除
For i = 0 To ThisDrawing.SelectionSets.Count - 1
If ThisDrawing.SelectionSets.Item(i).Name = "SelSet" Then
Set SelSet = ThisDrawing.SelectionSets.Item("SelSet")
SelSet.Delete
Exit For
End If
Next i
End If
Set SelSet = ThisDrawing.SelectionSets.Add("SelSet")
ThisDrawing.Utility.GetEntity entityObj, setpoint, "请拾取对象:"
nColor = entityObj.TrueColor.ColorIndex '获取颜色值
'0为block,256为bylayer,
Dim FilterType(0) As Integer
Dim FilterData(0) As Variant
Dim lyObj As AcadLayer
Set lyObj = ThisDrawing.Layers.Item(entityObj.Layer)
If nColor = 256 Then '颜色为bylayer时不能刷选??????????????????????
nColor = lyObj.TrueColor.ColorIndex
End If
FilterType(0) = 62
FilterData(0) = nColor
SelSet.Select acSelectionSetAll, , , FilterType, FilterData '将目标颜色所有对象添加到选择集中
SelSet.Highlight True
Exit Sub
errhandle:
If Err.Number = -2147352567 Then
ThisDrawing.Utility.Prompt "取消选择" & vbCrLf
Else
ThisDrawing.Utility.Prompt vbCrLf & Err.Number & vbCrLf
ThisDrawing.Utility.Prompt vbCrLf & Err.Description & vbCrLf
End If
End Sub
|
|