找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 619|回复: 0

[教学]:恭贺灯火重出江湖,送贺礼一份...

[复制链接]

已领礼包: 145个

财富等级: 日进斗金

发表于 2002-5-27 11:28:29 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
ADN开发资料,通过VBA如何获得块的常量属性


  1. [FONT=courier new]
  2. How to get the constant attributes of a blockref through VBA  
  3. ID    12559  
  4. Applies to:    AutoCAD 2000
  5. AutoCAD 2000I
  6. AutoCAD 2002

  7. Date    1/10/2002  

  8. This document is part of    Attribute   Block Reference   COM-ActiveX Interfaces   VBA     


  9. Question
  10. I have a drawing that has many different blocks, each block has three constant
  11. attributes (tags 'code' 'desc' and 'linfoot'). How do I get the block name,the
  12. attribute values, and find how many times the block is inserted and put this
  13. information into a spreadsheet using VBA?
  14. Answer
  15. You can get the block information from the block definition in the block table
  16. using VBA.

  17. The following sample demonstrates this by getting all the attributes of all the
  18. block references found in model space. You need to create a simple form which
  19. contains a listbox named ListBox1 and a button that starts the following
  20. procedure:


  21. Private Sub CommandButton1_Click()
  22.   Dim elem As Object
  23.   Dim block As AcadBlock
  24.   Dim item As Object
  25.   Dim Array1 As Variant
  26.   Dim count As Integer
  27.   Dim MBtest1 As String
  28.   Dim str As String
  29.   For Each elem In ThisDrawing.ModelSpace
  30.     If elem.EntityName = "AcDbBlockReference" Then
  31.         If elem.HasAttributes Then
  32.         Array1 = elem.GetAttributes
  33.         For count = LBound(Array1) To UBound(Array1)
  34.             If (Array1(count).EntityName) = "AcDbAttribute" Then
  35.                 MBtest1 = Array1(count).TagString & " - " &
  36. Array1(count).TextString
  37.                 ListBox1.AddItem MBtest1
  38.             End If
  39.         Next count
  40.         'Get the block definition from the block table
  41.         str = elem.Name
  42.         Set block = ThisDrawing.Blocks.item(str)
  43.         For Each item In block
  44.           str = item.EntityName
  45.          'Get the Constant attributes
  46.           If item.EntityName = "AcDbAttributeDefinition" Then
  47.             If item.Mode = acAttributeModeConstant Then
  48.               ListBox1.AddItem item.TagString & " - " & item.TextString
  49.             End If
  50.           End If
  51.         Next item         
  52.         End If
  53.     End If
  54.    Next elem
  55. End Sub
  56. [/FONT]
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-12-23 05:51 , Processed in 0.382456 second(s), 30 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表