- Sub GetLenth()
- Dim ExcelApp As New Excel.Application
- Dim ExcelWkbk As Excel.Workbook
- Set ExcelWkbk = ExcelApp.Workbooks.Add
- Dim i As Integer
- i = 1
- Dim Sel As AcadSelectionSet
- On Error Resume Next
- Set Sel = ThisDrawing.SelectionSets.Add("ss")
- If Err Then
- Err.Clear
- ThisDrawing.SelectionSets.Item("ss").Delete
- Set Sel = ThisDrawing.SelectionSets.Add("ss")
- End If
- On Error GoTo 0
- Dim gpCode(0) As Integer
- Dim dbValue(0) As Variant
- gpCode(0) = 8
- dbValue(0) = "图层1"
- Sel.Select acSelectionSetAll, , , gpCode, dbValue
- Dim Ent As AcadEntity
- With ExcelWkbk.Worksheets("sheet1")
- For Each Ent In Sel
- If Ent.ObjectName = "AcDbLine" Then
- .Range("A" & i) = i
- .Range("B" & i) = Ent.Length
- i = i + 1
- End If
- Next Ent
- End With
- ExcelApp.ActiveWorkbook.SaveAs "d:\AcadLen.xls"
- ExcelApp.Workbooks.Close
- ExcelApp.Quit
- Sel.Delete
- End Sub
以上程序仅保存“图层1”的线长。
|