马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
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:
- [FONT=courier new]
- Private Sub CommandButton1_Click()
- Dim elem As Object
- Dim block As AcadBlock
- Dim item As Object
- Dim Array1 As Variant
- Dim count As Integer
- Dim MBtest1 As String
- Dim str As String
- For Each elem In ThisDrawing.ModelSpace
- If elem.EntityName = "AcDbBlockReference" Then
- If elem.HasAttributes Then
- Array1 = elem.GetAttributes
- For count = LBound(Array1) To UBound(Array1)
- If (Array1(count).EntityName) = "AcDbAttribute" Then
- MBtest1 = Array1(count).TagString & " - " &
- Array1(count).TextString
- ListBox1.AddItem MBtest1
- End If
- Next count
- 'Get the block definition from the block table
- str = elem.Name
- Set block = ThisDrawing.Blocks.item(str)
- For Each item In block
- str = item.EntityName
- 'Get the Constant attributes
- If item.EntityName = "AcDbAttributeDefinition" Then
- If item.Mode = acAttributeModeConstant Then
- ListBox1.AddItem item.TagString & " - " & item.TextString
- End If
- End If
- Next item
- End If
- End If
- Next elem
- End Sub
- [/FONT]
|