- 积分
- 73549
- 明经币
- 个
- 注册时间
- 2001-6-7
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
发表于 2003-3-10 19:51:00
|
显示全部楼层
可以使用以下程序完成
Sub SelBlkSet()
Dim Blk As AcadBlockReference
Dim Ent As AcadEntity
Dim Pnt As Variant
Dim SelBlk As Boolean
Dim BlkName As String
On Error Resume Next
'选择对象并判断所选对象是否为图块
SelBlk = True
While SelBlk
ThisDrawing.Utility.GetEntity Ent, Pnt, "选择图块"
If Ent.ObjectName = "AcDbBlockReference" Then
Set Blk = Ent
BlkName = Blk.Name
SelBlk = False
End If
Wend
'创建空白选择集
Dim BlkSet As AcadSelectionSet
Set BlkSet = CreateSelectionSet
'建立选择集过滤器
Dim TypeArray As Variant
Dim DateArray As Variant
BuildFilter TypeArray, DateArray, 100, "AcDbBlockReference", 2, BlkName
'过滤出所要选择的图块
BlkSet.Select acSelectionSetAll, , , TypeArray, DateArray
'显示选定的图块名称及数量
Debug.Print "选定的图块名称为“" & BlkName & "”,数量为" & BlkSet.Count
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 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
而对于在电子表格中定义块,道理和在ACAD的VBA中一样 |
|