How to manipulate block attirubutes (value)?

How to manipulate block attirubutes (value)?

j.pavlicek
Collaborator Collaborator
1,249 Views
1 Reply
Message 1 of 2

How to manipulate block attirubutes (value)?

j.pavlicek
Collaborator
Collaborator

Hello,

I have block with (text) attributes (as you can see in an image below).acad_block_sample_99.png

 

When I find this block in modelspace in VBA, there is no property standing for these attributes in Watch.

acad_block_sample_99_vba.png

Is somehow possilbe to maipulate these attributes via VBA?

 

Thank you.



Inventor 2022, Windows 10 Pro
Sorry for bad English.
0 Likes
Accepted solutions (1)
1,250 Views
1 Reply
Reply (1)
Message 2 of 2

norman.yuan
Mentor
Mentor
Accepted solution

AcadBlockreference class does not have direct property/properties pointing to attributes (AcadAttributeReference) it contains. However, it has a method GetAttributes() that returns an array of AttributeReferences in this block reference. So, the code to change/update attribute value would roughly looks like:

 

Dim blk As AcadBlockreference

Dim atts As Variant

Dim att As AcadAttributeReference

Dim i As Integer

Set blk = (code to identify your target block reference)

If blk.HasAttributes Then

  atts = blk.GetAttributes()

  For i = 0 To Ubound(atts)

    Set att = atts(i)

    '' Then based on its Tag, assign corresponding value

    Select UCase(att.TagString)

      Case "INDEX":

        att.TextString="AAAAAA"

      Case "WHATEVER":

        att.Text="BBBBBB"

      CASE "...."

        att.TextString="...."

    End Select

  Next

End If

 

HTH

 

 

 

Norman Yuan

Drive CAD With Code

EESignature