Using the Get Attributes Method

Use the GetAttributes method of a BlockReference or MInsertBlock object to retrieve any associated AttributeReference objects. It returns an array, varAttributeRefs, that contains all the nonconstant attributes. This method has the following syntax:

varAttributeRefs = Object.GetAttributes()

The following example uses the Debug window to display information about each AttributeRef object associated with a block reference. Try it on an attributed block, such as the one created in the previous example.

Public Sub TestGetAttributes()

Dim varPick As Variant

Dim objEnt As AcadEntity

Dim objBRef As AcadBlockReference

Dim varAttribs As Variant

Dim strAttribs As String

Dim intI As Integer

On Error Resume Next

With ThisDrawing.Utility

'' get an entity from user

.GetEntity objEnt, varPick, vbCr & "Pick a block with attributes: If Err Then Exit Sub

'' cast it to a blockref Set objBRef = objEnt

'' exit if not a block If objBRef Is Nothing Then

.Prompt vbCr & "That wasn't a block." Exit Sub End If

'' exit if it has no attributes If Not objBRef.HasAttributes Then

.Prompt vbCr & "That block doesn't have attributes." Exit Sub End If

'' get the attributerefs varAttribs = objBRef.GetAttributes

'' show some information about each strAttribs = "Block Name: " & objBRef.Name & vbCrLf For intI = LBound(varAttribs) To UBound(varAttribs) strAttribs = strAttribs & " Tag(" & intI & "): " & _ varAttribs(intI).TagString & vbTab & " Value(" & intI & "): " & _ varAttribs(intI).TextString & vbCrLf Next

End With

MsgBox strAttribs End Sub

Using the GetConstantAttributes Method

Use the GetConstantAttributes method of a BlockReference or MInsertBlock object to retrieve associated constant Attribute objects. This method has the following syntax:

varAttributes = Object.GetConstantAttributes()

It returns an array, varAttributes, that contains the constant attributes. The following example uses the Debug window to display information about each constant Attribute object associated with a block reference. Try it on a block that has constant attributes, such as the one created earlier:

Public Sub TestGetConstantAttributes()

Dim varPick As Variant

Dim objEnt As AcadEntity

Dim objBRef As AcadBlockReference

Dim varAttribs As Variant

Dim strAttribs As String

Dim intI As Integer

On Error Resume Next With ThisDrawing.Utility

'' get an entity from user .GetEntity objEnt, varPick, vbCr & _

"Pick a block with constant attributes: " If Err Then Exit Sub

'' cast it to a blockref Set objBRef = objEnt

'' exit if not a block If objBRef Is Nothing Then

.Prompt vbCr & "That wasn't a block." Exit Sub End If

'' exit if it has no attributes If Not objBRef.HasAttributes Then

.Prompt vbCr & "That block doesn't have attributes." Exit Sub End If

'' get the constant attributes varAttribs = objBRef.GetConstantAttributes

'' show some information about each strAttribs = "Block Name: " & objBRef.Name & vbCrLf

For intI = LBound(varAttribs) To UBound(varAttribs)

strAttribs = strAttribs & " Tag(" & intI & "): " & _ varAttribs(intI).TagString & vbTab & "Value(" & intI & "): " & _ varAttribs(intI).TextString

Next End With

MsgBox strAttribs End Sub

+1 0

Post a comment