- 积分
- 10513
- 明经币
- 个
- 注册时间
- 2002-6-3
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
- 'frmBlock代码
- Private Sub CommandButton1_Click()
- If ListBox1.Text = "" Then Exit Sub
- If ListBox2.ListCount = 0 Then Exit Sub
- '返回选中的属性列表
- Dim s() As String
- Dim i As Integer
- Dim n As Integer
- For i = 0 To ListBox2.ListCount - 1
- If ListBox2.Selected(i) Then
- ReDim Preserve s(n)
- s(n) = ListBox2.List(i)
- n = n + 1
- End If
- Next
- If n = 0 Then Exit Sub
-
- On Error Resume Next
- '启动Excel
- Dim xlApp As Excel.Application
- Set xlApp = GetObject(, "Excel.Application")
- If Err Then
- Err.Clear
- Set xlApp = CreateObject("Excel.Application")
- If Err Then
- MsgBox "无法启动Excel,请检查系统!"
- Err.Clear
- Exit Sub
- End If
- End If
- xlApp.Visible = True
-
- On Error GoTo ErrTrap
- '创建工作簿
- Dim xlBook As Excel.Workbook
- If xlApp.Workbooks.Count = 0 Then xlApp.Workbooks.Add
- Set xlBook = xlApp.ActiveWorkbook
-
- '设置工作表
- Dim xlSheet As Excel.Worksheet
- Set xlSheet = xlBook.Worksheets(1)
- xlSheet.Range(xlSheet.UsedRange.Address).ClearContents
-
- On Error Resume Next
- '创建选择集
- Dim SSetObj As Object
- Set SSetObj = ThisDrawing.SelectionSets("BlockCount")
- If Err.Number <> 0 Then
- Err.Clear
- Set SSetObj = ThisDrawing.SelectionSets.Add("BlockCount")
- End If
- SSetObj.Clear
-
- On Error GoTo ErrTrap
- '创建过滤机制
- Dim fType(0 To 1) As Integer
- Dim fData(0 To 1) As Variant
- fType(0) = 0: fData(0) = "INSERT"
- fType(1) = 2: fData(1) = ListBox1.Text
- '选择名称为Name的所有块
- SSetObj.Select acSelectionSetAll, , , fType, fData
- '删除数组
- Erase fType: Erase fData
- If SSetObj.Count = 0 Then Exit Sub
- '输出块信息
- xlSheet.Cells(1, 1) = "块名"
- xlSheet.Cells(1, 2) = ListBox1.Text
- xlSheet.Cells(1, 3) = "数目"
- xlSheet.Cells(1, 4) = SSetObj.Count
- '输出属性标题
- For i = 0 To UBound(s)
- xlSheet.Cells(2, i + 1) = s(i)
- Next
-
- '枚举选择集
- Dim BlockRefObj As AcadBlockReference
- Dim EntObj As AcadEntity
- Dim AttRefs As Variant
- Dim j As Integer
- n = 3
- For Each EntObj In SSetObj
- If TypeOf EntObj Is AcadBlockReference Then
- Set BlockRefObj = EntObj
- If BlockRefObj.HasAttributes Then
- AttRefs = BlockRefObj.GetAttributes
- For i = 0 To UBound(AttRefs)
- For j = 0 To UBound(s)
- If AttRefs(i).TagString = s(j) Then
- xlSheet.Cells(n, j + 1) = AttRefs(i).TextString
- Exit For
- End If
- Next
- Next
- End If
- n = n + 1
- End If
- Next
-
- '删除选择集
- SSetObj.Clear
- SSetObj.Delete
- Set EntObj = Nothing
- Set BlockRefObj = Nothing
- Set SSetObj = Nothing
- Set xlSheet = Nothing
- Set xlApp = Nothing
- MsgBox "转换完毕! ", vbInformation
- Exit Sub
-
- ErrTrap:
- MsgBox "出错了,请检查程序!"
- On Error GoTo 0
- End Sub
- Private Sub CommandButton2_Click()
- Unload Me
- End Sub
- Private Sub ListBox1_Click()
- If ListBox1.Text = "" Then Exit Sub
- ListBox2.Clear
- '列表框的当前位置
- Dim idx As Integer
- idx = ListBox1.ListIndex
- '计算块的数目
- If IsNull(ListBox1.List(idx, 1)) Then
- ListBox1.List(idx, 1) = BlockCount(ListBox1.Text)
- End If
- '返回块
- Dim BlockObj As AcadBlock
- Set BlockObj = ThisDrawing.Blocks(ListBox1.Text)
- '枚举属性
- Dim AttObj As AcadAttribute
- Dim EntObj As AcadEntity
- For Each EntObj In BlockObj
- If TypeOf EntObj Is AcadAttribute Then
- Set AttObj = EntObj
- ListBox2.AddItem AttObj.TagString
- End If
- Next
- Set AttObj = Nothing
- Set EntObj = Nothing
- Set BlockObj = Nothing
- End Sub
- Private Sub UserForm_Initialize()
- Dim v As Variant
- Dim i As Integer
- Dim j As Integer
-
- On Error GoTo ErrTrap
- '块名、数目
- ListBox1.ColumnWidths = "50,25"
- '枚举块名
- Dim BlockObj As AcadBlock
- For Each BlockObj In ThisDrawing.Blocks
- '排除匿名块
- If Left(BlockObj.Name, 1) <> "*" Then
- ListBox1.AddItem BlockObj.Name
- End If
- Next
- Set BlockObj = Nothing
- Exit Sub
- ErrTrap:
- On Error GoTo 0
- End Sub
- '计算块的数目
- Private Function BlockCount(ByVal Name As String) As Integer
- BlockCount = 0
- If Name = "" Then Exit Function
- On Error Resume Next
- '创建选择集
- Dim SSetObj As Object
- Set SSetObj = ThisDrawing.SelectionSets("BlockCount")
- If Err.Number <> 0 Then
- Err.Clear
- Set SSetObj = ThisDrawing.SelectionSets.Add("BlockCount")
- End If
- SSetObj.Clear
-
- On Error GoTo ErrTrap
- '创建过滤机制
- Dim fType(0 To 1) As Integer
- Dim fData(0 To 1) As Variant
- fType(0) = 0: fData(0) = "INSERT"
- fType(1) = 2: fData(1) = Name
- '选择名称为Name的所有块
- SSetObj.Select acSelectionSetAll, , , fType, fData
- '返回块的数目
- BlockCount = SSetObj.Count
- '删除数组
- Erase fType: Erase fData
- '删除选择集
- SSetObj.Clear
- SSetObj.Delete
- Set SSetObj = Nothing
- Exit Function
-
- ErrTrap:
- MsgBox "出错了,请检查程序!"
- On Error GoTo 0
- End Function
DVB文件,请使用R2000以上版本打开。
FRM文件
截图
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?注册
x
评分
-
查看全部评分
|