-
- Sub ls()
- Dim ii As Integer
- Dim strLeft As String, strRight As String
- ii = 2
- Dim xlSheet1 As Worksheet, xlSheet2 As Worksheet
- Set xlSheet1 = xlApp.Sheets(1)
-
- Dim Ent As AcadBlock, Ee As AcadEntity
- Debug.Print "ModelSpace"
- Dim SSet As AcadSelectionSet
- On Error Resume Next
- '建立选择集
- ThisDrawing.SelectionSets("mccad").Delete
- Set SSet = ThisDrawing.SelectionSets.Add("mccad")
- '建立过滤器
- Dim fType(0) As Integer
- Dim fData(0) As Variant
- fType(0) = 0
- fData(0) = "DIMENSION"
- '选择过滤出图形中所有的标注对象
- SSet.Select acSelectionSetAll, , , fType, fData
- Dim i As Long
- For i = 0 To SSet.Count - 1
- xlSheet1.Cells(ii, 1).Value = SSet(i).ObjectName
- xlSheet1.Cells(ii, 2).Value = TypeName(SSet(i))
- xlSheet1.Cells(ii, 3).Value = "'" & SSet(i).Handle
- cc = SSet(i).Handle
- strLeft = Left(cc, Len(cc) - 2)
- strRight = "&H" & Right(cc, 2)
- xlSheet1.Cells(ii, 4).Value = strLeft + Hex(strRight + 1)
-
- ii = ii + 1
- Next
-
- ' For Each Ee In ThisDrawing.ModelSpace
- ' Next
- Set xlSheet1 = Nothing
-
- Set xlSheet2 = xlApp.Sheets(2)
- Debug.Print
- Debug.Print "Blocks"
- ii = 2
- For Each Ent In ThisDrawing.Blocks
- If TypeName(Ent) = "IAcadBlock" And Ent.Handle "55" Then
- xlSheet2.Cells(ii, 1).Value = Ent.ObjectName
- xlSheet2.Cells(ii, 2).Value = TypeName(Ent)
- xlSheet2.Cells(ii, 3).Value = "'" & Ent.Handle
- xlSheet2.Cells(ii, 4).Value = Ent.Count
- ii = ii + 1
- End If
- Next
- Set xlSheet2 = Nothing
-
- End Sub
- Function xlApp() As Object
- ' Dim xlApp As Object ' This Line ,Not set Excel , run Excel
- 'Dim xlsheet As Object
-
- ' 发生错误时跳到下一个语句继续执行
- On Error Resume Next
- ' 连接Excel应用程序
- Set xlApp = GetObject(, "Excel.Application")
-
- If Err.Number 0 Then
- Set xlApp = CreateObject("Excel.Application")
- xlApp.Visible = True
- xlApp.Workbooks.Add
- End If
- ' 返回当前活动的工作表
- End Function
|