Block Attribute VBA

Block Attribute VBA

AutocadVBANewbie
Explorer Explorer
659 Views
5 Replies
Message 1 of 6

Block Attribute VBA

AutocadVBANewbie
Explorer
Explorer

I am unable to change the TextString of a specific block on drawing using VBA.

 

I am trying to fetch the Tagstring and replace the Textstring with a new value.

 

Please guide.

 

0 Likes
660 Views
5 Replies
Replies (5)
Message 2 of 6

MakCADD
Advocate
Advocate

 

if attribute(number).tagstring="tagname"

attribute(number).textstring="value"

0 Likes
Message 3 of 6

AutocadVBANewbie
Explorer
Explorer

@MakCADD  Thankyou for your response.

 

I am using a similar structure but it doesn't seem to work.

 

Dim attributeZ As Object
Dim blockZs As Object
Dim intX As Integer

intX = 95

 

Set blockZs = actDoc.blocks("Sheet_2")
Set attributeZ = blockZs.Item(intX)


If attributeZ.TagString = "Drawing_Name" Then
attributeZ.Textstring = "XXXXXX"


End If

 

attributeZ.Update

0 Likes
Message 4 of 6

norman.yuan
Mentor
Mentor

Do you want to change block definition, or block reference (blocks that user see in AutoCAD)?

 

1. What your code does is to change attribute definition in the block definition, where the attribute's TextString is the attribute's default value when a block with that attribute is inserted into drawing (as BLOCK REFERENCE!).

2. Changes made to attribute definition in a block definition will not show up in the block references of that block definition. 

 

I suspect you actually want to do is change a block reference's attribute value. You may want to describe/explain in more details on what you are trying to do, against what (Block Definition, or Block Reference)?

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 5 of 6

AutocadVBANewbie
Explorer
Explorer

AutocadVBANewbie_0-1669007489419.png

@norman.yuan : This is a block on the drawing where I need to change attributes through VBA.

 

The code mentioned in my previous reply executes but no changes reflect on the drawing.

0 Likes
Message 6 of 6

MakCADD
Advocate
Advocate

attribute belongs to blockreference not to block

 

if blockreferencename=blockname then get attribute and then set attribute

0 Likes