乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 3|回复: 1

[编程交流] 如何导出区块信息

[复制链接]

16

主题

36

帖子

20

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
80
发表于 2022-7-6 12:25:54 | 显示全部楼层 |阅读模式
我有很多属性块。我想通过VBA将块信息和块属性存储到excel表中。
 
我该怎么办?
回复

使用道具 举报

1

主题

1069

帖子

1050

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
69
发表于 2022-7-6 13:44:15 | 显示全部楼层
 
这会让你开始
作者未知
 
 
  1. '' Request reference to Microsoft Excel XX.0 Object Library
  2. Option Explicit
  3. Public Sub WriteAttributes()
  4. Dim oSset As AcadSelectionSet
  5. Dim oEnt As AcadEntity
  6. Dim oBlkRef As AcadBlockReference
  7. Dim oAtt As AcadAttributeReference
  8. Dim varAtt As Variant
  9. Dim i As Long
  10. Dim ftype(1) As Integer
  11. Dim fdata(1) As Variant
  12. ftype(0) = 0: fdata(0) = "INSERT"
  13. ftype(1) = 66: fdata(1) = 1
  14. Dim dxftype As Variant
  15. Dim dxfdata As Variant
  16. dxftype = ftype
  17. dxfdata = fdata
  18. '---------------------
  19. Dim xlApp As Object
  20. Dim xlBook As Workbook
  21. Dim xlSheet As Worksheet
  22. Dim lngRow As Long, lngCol As Long
  23. '---------------------
  24. On Error Resume Next
  25. Set xlApp = GetObject(, "Excel.Application")
  26. If Err <> 0 Then
  27. Err.Clear
  28. Set xlApp = CreateObject("Excel.Application")
  29. If Err <> 0 Then
  30. MsgBox "Impossible to initialize an Excel.", vbExclamation
  31. End
  32. End If
  33. End If
  34. '---------------------
  35. On Error Resume Next
  36. Set oSset = ThisDrawing.SelectionSets.Item("$Attribs$")
  37. If Err Then
  38. Err.Clear
  39. Set oSset = ThisDrawing.SelectionSets.Add("$Attribs$")
  40. End If
  41. On Error GoTo Err_Control
  42. oSset.SelectOnScreen dxftype, dxfdata
  43. '---------------------
  44. xlApp.Visible = True
  45. Set xlBook = xlApp.Workbooks.Add
  46. xlBook.Sheets.Add.Name = 1
  47. Set xlSheet = xlBook.Sheets(1)
  48. lngRow = 1
  49. xlSheet.Cells(lngRow, 1).Value = "Block Name"
  50. xlSheet.Rows(1).Font.Bold = True
  51. xlSheet.Rows(1).Font.ColorIndex = 5
  52. '---------------------
  53. lngRow = 2
  54. For Each oEnt In oSset
  55. Set oBlkRef = oEnt
  56. If oBlkRef.IsDynamicBlock Then
  57. xlSheet.Cells(lngRow, 1).Value = oBlkRef.EffectiveName
  58. Else
  59. xlSheet.Cells(lngRow, 1).Value = oBlkRef.Name
  60. End If
  61. varAtt = oBlkRef.GetAttributes
  62. lngCol = 2
  63. For i = 0 To UBound(varAtt)
  64. Set oAtt = varAtt(i)
  65. xlSheet.Cells(lngRow, lngCol).Value = oAtt.TagString
  66. xlSheet.Cells(lngRow + 1, lngCol).Value = oAtt.TextString
  67. lngCol = lngCol + 1
  68. Next i
  69. lngRow = lngRow + 2
  70. Next oEnt
  71. '--------------------
  72. Dim oRange As Range
  73. Set oRange = xlSheet.UsedRange
  74. For i = 2 To oRange.Columns.Count
  75. xlSheet.Cells(1, i).Value = "Attribue " & CStr(i - 1)
  76. Next
  77. '--------------------
  78. xlSheet.Columns.HorizontalAlignment = xlHAlignLeft
  79. xlSheet.Columns.AutoFit
  80. xlBook.SaveAs ThisDrawing.Path & "\Attributes.xls"
  81. xlBook.Close
  82. '--------------------
  83. xlApp.Application.Quit
  84. Set xlApp = Nothing
  85. Set xlBook = Nothing
  86. Set xlSheet = Nothing
  87. '--------------------
  88. MsgBox "Excel file was saved as: " & vbCr & ThisDrawing.Path & "\Attributes.xls"
  89. '--------------------
  90. Err_Control:
  91. End Sub

 
~'J'~
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-5 06:22 , Processed in 0.343914 second(s), 56 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表