找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 1206|回复: 0

[分享]:通过VBA获得块定义属性

[复制链接]
发表于 2008-12-18 18:36:54 | 显示全部楼层 |阅读模式

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

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

×
How to get the constant attributes of a blockref through VBA  
ID    12559  
Applies to:    AutoCAD 2000
AutoCAD 2000I
AutoCAD 2002
  
This document is part of    Attribute   Block Reference   COM-ActiveX Interfaces   VBA     


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

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


  1. [FONT=courier new]
  2. Private Sub CommandButton1_Click()
  3.   Dim elem As Object
  4.   Dim block As AcadBlock
  5.   Dim item As Object
  6.   Dim Array1 As Variant
  7.   Dim count As Integer
  8.   Dim MBtest1 As String
  9.   Dim str As String
  10.   For Each elem In ThisDrawing.ModelSpace
  11.     If elem.EntityName = "AcDbBlockReference" Then
  12.         If elem.HasAttributes Then
  13.         Array1 = elem.GetAttributes
  14.         For count = LBound(Array1) To UBound(Array1)
  15.             If (Array1(count).EntityName) = "AcDbAttribute" Then
  16.                 MBtest1 = Array1(count).TagString & " - " &
  17. Array1(count).TextString
  18.                 ListBox1.AddItem MBtest1
  19.             End If
  20.         Next count
  21.         'Get the block definition from the block table
  22.         str = elem.Name
  23.         Set block = ThisDrawing.Blocks.item(str)
  24.         For Each item In block
  25.           str = item.EntityName
  26.          'Get the Constant attributes
  27.           If item.EntityName = "AcDbAttributeDefinition" Then
  28.             If item.Mode = acAttributeModeConstant Then
  29.               ListBox1.AddItem item.TagString & " - " & item.TextString
  30.             End If
  31.           End If
  32.         Next item         
  33.         End If
  34.     End If
  35.    Next elem
  36. End Sub

  37. [/FONT]
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2024-11-22 01:56 , Processed in 0.171712 second(s), 32 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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